Java 类com.hp.hpl.jena.query.QueryExecution 实例源码

项目:DocIT    文件:Containment.java   
public static boolean checkContainment(CompanyModel c){
    String queryString = 
        "ASK" +
            // check whether any manager is an employee in any other department
            "{?dept1"        + " <" + c.MANAGER   + "> " + "?manager"         + ". " +
            " ?dept2"        + " <" + c.EMPLOYEES + "> " + "?employees1"      + ". " +
            " ?employees1"   + " <" + RDFS.member + "> " + "?employee1"       + ". " +
            " FILTER (?manager = ?employee1) " +

            // check whether any employee occurs more than once
            " ?dept3 "       + " <" + c.EMPLOYEES + "> " + "?employees2"      + ". " +
            " ?employees2"   + " <" + RDFS.member + "> " + "?employee2"       + ". " +
            " FILTER (?employee1 = ?employee2)" +

            // check whether any department occurs more than once
            " ?upperDept1"   + " <" + c.DEPTS     + "> " + "?dept4"           + ". " +
            " ?upperDept2"   + " <" + c.DEPTS     + "> " + "?dept5"           + ". " +
            " FILTER (?dept4 = ?dept5) " +
            "}";

    Query query = QueryFactory.create(queryString);
    QueryExecution qe = QueryExecutionFactory.create(query, c.getModel());
    boolean out = qe.execAsk();
    qe.close();
    return !out;
}
项目:ontonethub    文件:IndexingJob.java   
private List<Statement> expandSubClasses(Model model){
    List<Statement> stmts = new ArrayList<Statement>();


    String sparql = "PREFIX rdfs: <" + RDFS.getURI() + ">"
            + "SELECT DISTINCT ?class ?synonym "
            + "WHERE { "
            + "?class rdfs:subClassOf+ ?subClass . "
            + "?subClass <" + synonym + "> ?synonym"
            + "}";

    Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
    QueryExecution queryExecution = QueryExecutionFactory.create(query, model);
    ResultSet resultSet = queryExecution.execSelect();
    resultSet.forEachRemaining(querySolution -> {
        stmts.add(new StatementImpl(querySolution.getResource("class"), synonym, querySolution.getLiteral("synonym")));
    });
    return stmts;
}
项目:ontonethub    文件:IndexingJob.java   
private List<Statement> expandSubProperties(Model model){
    List<Statement> stmts = new ArrayList<Statement>();

    String sparql = "PREFIX rdfs: <" + RDFS.getURI() + ">"
            + "SELECT DISTINCT ?property ?synonym "
            + "WHERE { "
            + "?property rdfs:subPropertyOf+ ?subProperty . "
            + "?subProperty <" + synonym + "> ?synonym"
            + "}";

    Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
    QueryExecution queryExecution = QueryExecutionFactory.create(query, model);
    ResultSet resultSet = queryExecution.execSelect();
    resultSet.forEachRemaining(querySolution -> {
        stmts.add(new StatementImpl(querySolution.getResource("property"), synonym, querySolution.getLiteral("synonym")));
    });
    return stmts;
}
项目:r2rml-kit    文件:ProcessorTestBase.java   
public static Collection<Object[]> getTestListFromManifest(String manifestFileURL) {
        // We'd like to use FileManager.loadModel() but it doesn't work on jar: URLs
//      Model m = FileManager.get().loadModel(manifestFileURL);
        Model m = ModelFactory.createDefaultModel();
        m.read(manifestFileURL, "TURTLE");

        IRI baseIRI = D2RQTestUtil.createIRI(m.getNsPrefixURI("base"));
        ResultSet rs = QueryExecutionFactory.create(TEST_CASE_LIST, m).execSelect();
        List<Object[]> result = new ArrayList<Object[]>();
        while (rs.hasNext()) {
            QuerySolution qs = rs.next();
            Resource mapping = qs.getResource("mapping");
            Resource schema = qs.getResource("schema");
//          if (!mapping.getLocalName().equals("constant-object.ttl")) continue;
            QueryExecution qe = QueryExecutionFactory.create(TEST_CASE_TRIPLES, m);
            qe.setInitialBinding(qs);
            Model expectedTriples = qe.execConstruct();
            result.add(new Object[]{baseIRI.relativize(mapping.getURI()).toString(), mapping.getURI(), 
                    schema.getURI(), expectedTriples});
        }
        return result;
    }
项目:r2rml-kit    文件:MappingGeneratorTest.java   
@Parameters(name="{index}: {0}")
    public static Collection<Object[]> getTestLists() {
        Model m = D2RQTestUtil.loadTurtle(MANIFEST_FILE);
        IRI baseIRI = D2RQTestUtil.createIRI(m.getNsPrefixURI("base"));
        ResultSet rs = QueryExecutionFactory.create(TEST_CASE_LIST, m).execSelect();
        List<Object[]> result = new ArrayList<Object[]>();
        while (rs.hasNext()) {
            QuerySolution qs = rs.next();
            Resource testCase = qs.getResource("case");
//          if (!case.getLocalName().equals("expression")) continue;
            QueryExecution qe = QueryExecutionFactory.create(TEST_CASE_TRIPLES, m);
            qe.setInitialBinding(qs);
            Model expectedTriples = qe.execConstruct();
            result.add(new Object[]{
                    baseIRI.relativize(testCase.getURI()).toString(), 
                    qs.getLiteral("sql").getLexicalForm(), 
                    expectedTriples});
        }
        return result;
    }
项目:BimSPARQL    文件:SPINInferencesWithoutConstructor.java   
/**
 * Runs a given Jena Query on a given instance and adds the inferred triples
 * to a given Model.
 * @param queryWrapper  the wrapper of the CONSTRUCT query to execute
 * @param queryModel  the query Model
 * @param newTriples  the Model to write the triples to
 * @param instance  the instance to run the inferences on
 * @param checkContains  true to only call add if a Triple wasn't there yet
 * @return true if changes were done (only meaningful if checkContains == true)
 */
public static boolean runQueryOnInstance(QueryWrapper queryWrapper, Model queryModel, Model newTriples, Resource instance, boolean checkContains) {
    boolean changed = false;
    QueryExecution qexec = ARQFactory.get().createQueryExecution(queryWrapper.getQuery(), queryModel);
    QuerySolutionMap bindings = new QuerySolutionMap();
    bindings.add(SPIN.THIS_VAR_NAME, instance);
    Map<String,RDFNode> initialBindings = queryWrapper.getTemplateBinding();
    if(initialBindings != null) {
        for(String varName : initialBindings.keySet()) {
            RDFNode value = initialBindings.get(varName);
            bindings.add(varName, value);
        }
    }
    qexec.setInitialBinding(bindings);
    Model cm = qexec.execConstruct();
    StmtIterator cit = cm.listStatements();
    while(cit.hasNext()) {
        Statement s = cit.nextStatement();
        if(!checkContains || !queryModel.contains(s)) {
            changed = true;
            newTriples.add(s);
        }
    }
    return changed;
}
项目:freme-ner    文件:SPARQLProcessor.java   
private Set<String> getTypesFromSPARQL(String sparqlQueryString) {

        Query query = QueryFactory.create(sparqlQueryString);
        QueryExecution qexec = QueryExecutionFactory.sparqlService(this.endpoint, query);
        Set<String> types = new HashSet<>();

        ResultSet results = qexec.execSelect();
        while(results.hasNext()) {
            QuerySolution qs = results.next();
            Resource type = qs.getResource("?type");
            types.add(type.getURI());
        }

        qexec.close();
        return types;
    }
项目:StreamEventCoreference    文件:OwlReader.java   
static void readOwlFile (String pathToOwlFile) {
        OntModel ontologyModel =
                ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
        ontologyModel.read(pathToOwlFile, "RDF/XML-ABBREV");
       // OntClass myClass = ontologyModel.getOntClass("namespace+className");

        OntClass myClass = ontologyModel.getOntClass(ResourcesUri.nwr+"domain-ontology#Motion");
        System.out.println("myClass.toString() = " + myClass.toString());
        System.out.println("myClass.getSuperClass().toString() = " + myClass.getSuperClass().toString());

        //List list =
              //  namedHierarchyRoots(ontologyModel);


       Iterator i = ontologyModel.listHierarchyRootClasses()
                .filterDrop( new Filter() {
                    public boolean accept( Object o ) {
                        return ((Resource) o).isAnon();
                    }} ); ///get all top nodes and excludes anonymous classes

       // Iterator i = ontologyModel.listHierarchyRootClasses();
        while (i.hasNext()) {
            System.out.println(i.next().toString());
/*            OntClass ontClass = ontologyModel.getOntClass(i.next().toString());
            if (ontClass.hasSubClass()) {

            }*/
        }

        String q = createSparql("event", "<http://www.newsreader-project.eu/domain-ontology#Motion>");
        System.out.println("q = " + q);
        QueryExecution qe = QueryExecutionFactory.create(q,
                ontologyModel);
        for (ResultSet rs = qe.execSelect() ; rs.hasNext() ; ) {
            QuerySolution binding = rs.nextSolution();
            System.out.println("binding = " + binding.toString());
            System.out.println("Event: " + binding.get("event"));
        }

        ontologyModel.close();
    }
项目:sdh-vocabulary    文件:VocabularyTest.java   
@Test
public void testMetric_TotalBuilds() {
    Query query =
        QueryFactory.
            create(
                loadResource("/metrics/total_builds.sparql"));
    QueryExecution queryExecution = null;
    try {
        queryExecution = QueryExecutionFactory.create(query, buildsDataSet());
        ResultSet results = queryExecution.execSelect();
        for(; results.hasNext();) {
            QuerySolution solution = results.nextSolution();
            long buildId = solution.getLiteral("total_builds").getLong();
            System.out.printf("Total builds: %d%n",buildId);
        }
    } finally {
        if (queryExecution != null) {
            queryExecution.close();
        }
    }
}
项目:sdh-vocabulary    文件:VocabularyTest.java   
@Test
public void testMetric_TotalExecutions_Global() {
    Query query =
        QueryFactory.
            create(
                loadResource("/metrics/total_executions_global.sparql"));
    QueryExecution queryExecution = null;
    try {
        queryExecution = QueryExecutionFactory.create(query, executionsDataSet());
        ResultSet results = queryExecution.execSelect();
        for(; results.hasNext();) {
            QuerySolution solution = results.nextSolution();
            long total_executions = solution.getLiteral("total_executions").getLong();
            System.out.printf("Total executions: %d%n",total_executions);
        }
    } finally {
        if (queryExecution != null) {
            queryExecution.close();
        }
    }
}
项目:sdh-vocabulary    文件:VocabularyTest.java   
@Test
public void testMetric_TotalExecutions_PerBuild() {
    Query query =
        QueryFactory.
            create(
                loadResource("/metrics/total_executions_per_build.sparql"));
    QueryExecution queryExecution = null;
    try {
        queryExecution = QueryExecutionFactory.create(query, executionsDataSet());
        ResultSet results = queryExecution.execSelect();
        for(; results.hasNext();) {
            QuerySolution solution = results.nextSolution();
            long total_executions = solution.getLiteral("total_executions").getLong();
            String buildId = shorten(solution.getResource("build").getURI());
            System.out.printf("Total executions of build %s: %d%n",buildId,total_executions);
        }
    } finally {
        if (queryExecution != null) {
            queryExecution.close();
        }
    }
}
项目:sdh-vocabulary    文件:VocabularyTest.java   
@Test
public void testMetric_TotalSuccesfulExecutions_Global() {
    Query query =
        QueryFactory.
            create(
                loadResource("/metrics/total_succesful_executions_global.sparql"));
    QueryExecution queryExecution = null;
    try {
        queryExecution = QueryExecutionFactory.create(query, executionsDataSet());
        ResultSet results = queryExecution.execSelect();
        for(; results.hasNext();) {
            QuerySolution solution = results.nextSolution();
            long total_executions = solution.getLiteral("total_executions").getLong();
            System.out.printf("Total succesful executions: %d%n",total_executions);
        }
    } finally {
        if (queryExecution != null) {
            queryExecution.close();
        }
    }
}
项目:sdh-vocabulary    文件:VocabularyTest.java   
@Test
public void testMetric_TotalSuccesfulExecutions_Global_Period() {
    Query query =
        QueryFactory.
            create(
                loadResource("/metrics/total_succesful_executions_global_period.sparql"));
    QueryExecution queryExecution = null;
    try {
        queryExecution = QueryExecutionFactory.create(query, executionsDataSet());
        ResultSet results = queryExecution.execSelect();
        for(; results.hasNext();) {
            QuerySolution solution = results.nextSolution();
            long total_executions = solution.getLiteral("total_executions").getLong();
            String day = solution.getLiteral("day").getString();
            System.out.printf("Total succesful executions [%s]: %d%n",day,total_executions);
        }
    } finally {
        if (queryExecution != null) {
            queryExecution.close();
        }
    }
}
项目:sdh-vocabulary    文件:VocabularyTest.java   
@Test
public void testMetric_TotalSuccesfulExecutions_PerBuild() {
    Query query =
        QueryFactory.
            create(
                loadResource("/metrics/total_succesful_executions_per_build.sparql"));
    QueryExecution queryExecution = null;
    try {
        queryExecution = QueryExecutionFactory.create(query, executionsDataSet());
        ResultSet results = queryExecution.execSelect();
        for(; results.hasNext();) {
            QuerySolution solution = results.nextSolution();
            long total_executions = solution.getLiteral("total_executions").getLong();
            String buildId = shorten(solution.getResource("build").getURI());
            System.out.printf("Total succesful executions of build %s: %d%n",buildId,total_executions);
        }
    } finally {
        if (queryExecution != null) {
            queryExecution.close();
        }
    }
}
项目:sdh-vocabulary    文件:VocabularyTest.java   
@Test
public void testMetric_TotalBrokenExecutions_Global() {
    Query query =
        QueryFactory.
            create(
                loadResource("/metrics/total_broken_executions_global.sparql"));
    QueryExecution queryExecution = null;
    try {
        queryExecution = QueryExecutionFactory.create(query, executionsDataSet());
        ResultSet results = queryExecution.execSelect();
        for(; results.hasNext();) {
            QuerySolution solution = results.nextSolution();
            long total_executions = solution.getLiteral("total_executions").getLong();
            System.out.printf("Total broken executions: %d%n",total_executions);
        }
    } finally {
        if (queryExecution != null) {
            queryExecution.close();
        }
    }
}
项目:sdh-vocabulary    文件:VocabularyTest.java   
@Test
public void testMetric_TotalBrokenExecutions_PerBuild() {
    Query query =
        QueryFactory.
            create(
                loadResource("/metrics/total_broken_executions_per_build.sparql"));
    QueryExecution queryExecution = null;
    try {
        queryExecution = QueryExecutionFactory.create(query, executionsDataSet());
        ResultSet results = queryExecution.execSelect();
        for(; results.hasNext();) {
            QuerySolution solution = results.nextSolution();
            long total_executions = solution.getLiteral("total_executions").getLong();
            String buildId = shorten(solution.getResource("build").getURI());
            System.out.printf("Total broken executions of build %s: %d%n",buildId,total_executions);
        }
    } finally {
        if (queryExecution != null) {
            queryExecution.close();
        }
    }
}
项目:DoSeR    文件:MainEvaluation.java   
public String getRedirect(final String entityUri) {
    final String query = "SELECT ?types WHERE{ <" + entityUri
            + "> <http://dbpedia.org/ontology/wikiPageRedirects> ?types. }";
    ResultSet results = null;
    QueryExecution qexec = null;
    try {
        final com.hp.hpl.jena.query.Query cquery = QueryFactory
                .create(query);
        qexec = QueryExecutionFactory.create(cquery, redirects);
        results = qexec.execSelect();
    } catch (final QueryException e) {
        Logger.getRootLogger().error(e.getStackTrace());
    } finally {
        if (results != null) {
            while (results.hasNext()) {
                final QuerySolution sol = results.nextSolution();
                final String type = sol.getResource("types").toString();
                return type;
            }
        }
    }
    return null;
}
项目:DoSeR    文件:LimayeGroundtruthAnnotationParser.java   
private String checkAvailability(String resource) {
    try {
        Query query = QueryFactory
                .create("SELECT ?label WHERE{ <"
                        + resource
                        + "> <http://www.w3.org/2000/01/rdf-schema#label> ?label. }");
        QueryExecution qe = QueryExecutionFactory.create(query, this.m_l);
        ResultSet results = qe.execSelect();
        if (results.hasNext()) {
            return resource;
        }
    } catch (Exception e) {
        return "";
    }
    return "";
}
项目:DoSeR    文件:LimayeGroundtruthAnnotationParser.java   
private String checkRedirects(String resource) {
    String result = resource;
    try {

        Query query = QueryFactory
                .create("SELECT ?redirect WHERE{ <"
                        + resource
                        + "> <http://dbpedia.org/ontology/wikiPageRedirects> ?redirect. }");
        QueryExecution qe = QueryExecutionFactory.create(query, this.m);
        ResultSet results = qe.execSelect();
        while (results.hasNext()) {
            QuerySolution sol = results.nextSolution();
            result = sol.getResource("redirect").getURI();
        }
    } catch (Exception e) {
        return resource;
    }
    return result;
}
项目:DoSeR    文件:LimayeAnnotationParserWebTables.java   
private String checkAvailability(String resource) {
    try {
        Query query = QueryFactory
                .create("SELECT ?label WHERE{ <"
                        + resource
                        + "> <http://www.w3.org/2000/01/rdf-schema#label> ?label. }");
        QueryExecution qe = QueryExecutionFactory.create(query, this.m_l);
        ResultSet results = qe.execSelect();
        if (results.hasNext()) {
            return resource;
        }
    } catch (Exception e) {
        return "";
    }
    return "";
}
项目:DoSeR    文件:LimayeAnnotationParserWebTables.java   
private String checkRedirects(String resource) {
    String result = resource;
    try {

        Query query = QueryFactory
                .create("SELECT ?redirect WHERE{ <"
                        + resource
                        + "> <http://dbpedia.org/ontology/wikiPageRedirects> ?redirect. }");
        QueryExecution qe = QueryExecutionFactory.create(query, this.m);
        ResultSet results = qe.execSelect();
        while (results.hasNext()) {
            QuerySolution sol = results.nextSolution();
            result = sol.getResource("redirect").getURI();
        }
    } catch (Exception e) {
        return resource;
    }
    return result;
}
项目:DoSeR    文件:FullyEvaluateCategories.java   
private Set<String> queryEntitiesFromCategory(final String catUri) {
    Set<String> set = new HashSet<String>();
    final String query = "SELECT ?entities WHERE{ ?entities <http://purl.org/dc/terms/subject> <"
            + catUri + ">. }";
    try {
        final com.hp.hpl.jena.query.Query cquery = QueryFactory
                .create(query);
        final QueryExecution qexec = QueryExecutionFactory
                .create(cquery, m);
        final ResultSet results = qexec.execSelect();
        while (results.hasNext()) {
            final QuerySolution sol = results.nextSolution();
            set.add(sol.getResource("entities").getURI()
                    .replaceAll("http://dbpedia.org/resource/", ""));
        }

    } catch (final QueryException e) {
        Logger.getRootLogger().error(e.getStackTrace());
    }
    return set;
}
项目:DoSeR    文件:EvaluatePureDbpediaCategories.java   
private String queryEntitiesFromCategory(final String catUri) {
    String res = null;

    final String query = "SELECT ?entities WHERE{ ?entities <http://purl.org/dc/terms/subject> <"
            + catUri + ">. }";
    try {
        final com.hp.hpl.jena.query.Query cquery = QueryFactory
                .create(query);
        final QueryExecution qexec = QueryExecutionFactory
                .create(cquery, m);
        final ResultSet results = qexec.execSelect();
        List<String> entities = new LinkedList<String>();
        while (results.hasNext()) {
            final QuerySolution sol = results.nextSolution();
            entities.add(sol.getResource("entities").getURI());
        }
        if (entities.size() != 0) {
            int randomNr = this.random.nextInt(entities.size());
            return entities.get(randomNr);
        }

    } catch (final QueryException e) {
        Logger.getRootLogger().error(e.getStackTrace());
    }
    return res;
}
项目:DoSeR    文件:DbpediaGraphModification.java   
private boolean hasSubCategory(String uri) {
    final String query = "SELECT ?entities WHERE{ ?types <http://www.w3.org/2004/02/skos/core#broader> <"
            + uri + ">. }";
    boolean hasSubtype = false;
    try {
        final com.hp.hpl.jena.query.Query cquery = QueryFactory
                .create(query);
        final QueryExecution qexec = QueryExecutionFactory
                .create(cquery, skosModel);
        final ResultSet results = qexec.execSelect();
        while (results.hasNext()) {
            hasSubtype = true;
            break;
        }

    } catch (final QueryException e) {
        Logger.getRootLogger().error(e.getStackTrace());
    }
    return hasSubtype;
}
项目:DoSeR    文件:DbpediaGraphModification.java   
private Set<String> queryEntitiesFromCategory(final String catUri) {
    Set<String> set = new HashSet<String>();
    final String query = "SELECT ?entities WHERE{ ?entities <http://purl.org/dc/terms/subject> <"
            + catUri + ">. }";
    try {
        final com.hp.hpl.jena.query.Query cquery = QueryFactory
                .create(query);
        final QueryExecution qexec = QueryExecutionFactory
                .create(cquery, m);
        final ResultSet results = qexec.execSelect();
        while (results.hasNext()) {
            final QuerySolution sol = results.nextSolution();
            set.add(sol.getResource("entities").getURI()
                    .replaceAll("http://dbpedia.org/resource/", ""));
        }

    } catch (final QueryException e) {
        Logger.getRootLogger().error(e.getStackTrace());
    }
    return set;
}
项目:DoSeR    文件:Sampling.java   
private String queryEntitiesFromCategory(final String catUri) {
    String res = null;

    final String query = "SELECT ?entities WHERE{ ?entities <http://purl.org/dc/terms/subject> <"
            + catUri + ">. }";
    try {
        final com.hp.hpl.jena.query.Query cquery = QueryFactory
                .create(query);
        final QueryExecution qexec = QueryExecutionFactory
                .create(cquery, m);
        final ResultSet results = qexec.execSelect();
        List<String> entities = new LinkedList<String>();
        while (results.hasNext()) {
            final QuerySolution sol = results.nextSolution();
            entities.add(sol.getResource("entities").getURI());
        }
        if (entities.size() != 0) {
            int randomNr = this.random.nextInt(entities.size());
            return entities.get(randomNr);
        }

    } catch (final QueryException e) {
        Logger.getRootLogger().error(e.getStackTrace());
    }
    return res;
}
项目:DoSeR    文件:TimeNumberDisambiguation.java   
private String getRedirect(String uri) {
    final Model model = DisambiguationMainService.getInstance().getDBpediaRedirects();
    final String query = "SELECT ?label WHERE{ <" + uri
            + "> <http://dbpedia.org/ontology/wikiPageRedirects> ?label. }";
    ResultSet results = null;
    QueryExecution qexec = null;
    String redirect = null;
    try {
        final com.hp.hpl.jena.query.Query cquery = QueryFactory.create(query);
        qexec = QueryExecutionFactory.create(cquery, model);
        results = qexec.execSelect();
    } catch (final QueryException e) {
        Logger.getRootLogger().error(e.getStackTrace());
    } finally {
        if (results.hasNext()) {
            final QuerySolution sol = results.nextSolution();
            redirect = sol.getResource("label").getURI();
        }
    }
    return redirect;
}
项目:DoSeR    文件:RDFGraphOperations.java   
public static Set<Type> getRDFTypesFromEntity(final String entityUri) {
    Set<Type> set = new HashSet<Type>();
    final Model model = DisambiguationMainService.getInstance().getDBPediaInstanceTypes();
    final String query = "SELECT ?types WHERE{ <" + entityUri
            + "> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?types. }";
    ResultSet results = null;
    QueryExecution qexec = null;
    try {
        final com.hp.hpl.jena.query.Query cquery = QueryFactory
                .create(query);
        qexec = QueryExecutionFactory.create(cquery, model);
        results = qexec.execSelect();
    } catch (final QueryException e) {
        Logger.getRootLogger().error(e.getStackTrace());
    } finally {
        if (results != null) {
            while (results.hasNext()) {
                final QuerySolution sol = results.nextSolution();
                final String type = sol.getResource("types").toString();
                set.add(new Type("", type, true, 0));
            }
        }
    }
    return set;
}
项目:DoSeR    文件:RDFGraphOperations.java   
public static String getDbPediaDescription(final String uri)
        throws QueryException {
    String res = null;
    final Model model = DisambiguationMainService.getInstance()
            .getDBPediaDescription();
    final String query = "SELECT ?description WHERE{ <" + uri
            + "> <http://dbpedia.org/ontology/abstract> ?description. }";
    ResultSet results = null; // NOPMD by quh on 14.02.14 10:04
    QueryExecution qexec = null;
    try {
        final com.hp.hpl.jena.query.Query cquery = QueryFactory
                .create(query);
        qexec = QueryExecutionFactory.create(cquery, model);
        results = qexec.execSelect();
    } finally {
        if ((results != null) && results.hasNext()) {
            res = results.nextSolution().getLiteral("description")
                    .getString();
        }
        if (qexec != null) {
            qexec.close();
        }
    }
    return res;
}
项目:DoSeR    文件:RDFGraphOperations.java   
public static List<String> getDbPediaLabel(final String uri)
        throws QueryException {
    final List<String> labellist = new LinkedList<String>();

    final Model model = DisambiguationMainService.getInstance()
            .getDBPediaLabels();
    final String query = "SELECT ?label WHERE{ <" + uri
            + "> <http://www.w3.org/2000/01/rdf-schema#label> ?label. }";
    ResultSet results = null; // NOPMD by quh on 14.02.14 10:04
    QueryExecution qexec = null;

    final com.hp.hpl.jena.query.Query cquery = QueryFactory.create(query);
    qexec = QueryExecutionFactory.create(cquery, model);
    results = qexec.execSelect();

    if (results != null) {
        while (results.hasNext()) {
            final QuerySolution sol = results.nextSolution();
            final String label = sol.getLiteral("label").getLexicalForm();
            labellist.add(label);
        }
        qexec.close();
    }
    return labellist;
}
项目:DoSeR    文件:RDFGraphOperations.java   
public static List<String> getDbPediaLabel_GER(final String uri)
        throws QueryException {
    final List<String> labellist = new LinkedList<String>();

    final Model model = DisambiguationMainService.getInstance()
            .getDBPediaLabels_GER();
    final String query = "SELECT ?label WHERE{ <" + uri
            + "> <http://www.w3.org/2000/01/rdf-schema#label> ?label. }";
    ResultSet results = null; // NOPMD by quh on 14.02.14 10:04
    QueryExecution qexec = null;

    final com.hp.hpl.jena.query.Query cquery = QueryFactory.create(query);
    qexec = QueryExecutionFactory.create(cquery, model);
    results = qexec.execSelect();

    if (results != null) {
        while (results.hasNext()) {
            final QuerySolution sol = results.nextSolution();
            final String label = sol.getLiteral("label").getLexicalForm();
            labellist.add(label);
        }
        qexec.close();
    }
    return labellist;
}
项目:DoSeR    文件:RDFGraphOperations.java   
private static String queryDbPediaCategoryLabel(final String catUri) {
    String res = null;
    final Model model = DisambiguationMainService.getInstance()
            .getDBPediaCategoryLabels();

    final String query = "SELECT ?label WHERE{ <" + catUri
            + "> <http://www.w3.org/2000/01/rdf-schema#label> ?label. }";
    try {
        final com.hp.hpl.jena.query.Query cquery = QueryFactory
                .create(query);
        final QueryExecution qexec = QueryExecutionFactory.create(cquery,
                model);
        final ResultSet results = qexec.execSelect(); // NOPMD by quh on
                                                        // 18.02.14 15:05
        while (results.hasNext()) {
            final QuerySolution sol = results.nextSolution();
            final String name = sol.getLiteral("label").getLexicalForm();
            res = name;
        }
    } catch (final QueryException e) {
        Logger.getRootLogger().error(e.getStackTrace());
    }
    return res;
}
项目:DoSeR    文件:RDFGraphOperations.java   
private static String queryDbPediaCategoryLabel_GER(final String catUri) {
    String res = null;
    final Model model = DisambiguationMainService.getInstance()
            .getDBPediaCategoryLabels_GER();

    final String query = "SELECT ?label WHERE{ <" + catUri
            + "> <http://www.w3.org/2000/01/rdf-schema#label> ?label. }";
    try {
        final com.hp.hpl.jena.query.Query cquery = QueryFactory
                .create(query);
        final QueryExecution qexec = QueryExecutionFactory.create(cquery,
                model);
        final ResultSet results = qexec.execSelect(); // NOPMD by quh on
                                                        // 18.02.14 15:05
        while (results.hasNext()) {
            final QuerySolution sol = results.nextSolution();
            final String name = sol.getLiteral("label").getLexicalForm();
            // RDFHack ToDo: Inform how to resolve the dbpedia tql files correctly

            res = name;
        }
    } catch (final QueryException e) {
        Logger.getRootLogger().error(e.getStackTrace());
    }
    return res;
}
项目:DoSeR    文件:RDFGraphOperations.java   
public static List<Type> queryYagoCategories(final String uri) {
    final Model model = DisambiguationMainService.getInstance()
            .getYagoTransitiveTypes();

    final List<Type> types = new LinkedList<Type>();
    final String query = "SELECT ?type WHERE{ <"
            + uri
            + "> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type. }";
    try {
        final com.hp.hpl.jena.query.Query que = QueryFactory.create(query);
        final QueryExecution qexec = QueryExecutionFactory.create(que,
                model);
        final ResultSet results = qexec.execSelect(); // NOPMD by quh on
                                                        // 18.02.14 15:05
        while (results.hasNext()) {
            final QuerySolution sol = results.nextSolution();
            final String name = sol.getResource("type").toString();
            types.add(new Type("", name, true, 0));
        }
    } catch (final QueryException e) {
        Logger.getRootLogger().error(e.getStackTrace());
    }
    return types;
}
项目:DoSeR    文件:RDFGraphOperations.java   
private static String queryYagoCategoryLabel(final String catUri) {
    String res = null;
    final Model model = DisambiguationMainService.getInstance()
            .getYagoCategoryLabels();

    final String query = "SELECT ?label WHERE{ <" + catUri
            + "> <http://www.w3.org/2004/02/skos/core#> ?label. }";
    try {
        final com.hp.hpl.jena.query.Query que = QueryFactory.create(query);
        final QueryExecution qexec = QueryExecutionFactory.create(que,
                model);
        final ResultSet results = qexec.execSelect(); // NOPMD by quh on
                                                        // 18.02.14 15:05
        while (results.hasNext()) {
            final QuerySolution sol = results.nextSolution();
            final String name = sol.getLiteral("label").getLexicalForm();
            res = name;
        }
    } catch (final QueryException e) {
        Logger.getRootLogger().error(e.getStackTrace());
    }
    return res;
}
项目:DoSeR    文件:CreateDBpediaIndexV2.java   
public List<String> getDbPediaLabel(final String uri) throws QueryException, QueryParseException {
    final List<String> labellist = new LinkedList<String>();
    try {
        final String query = "SELECT ?label WHERE{ <" + uri
                + "> <http://www.w3.org/2000/01/rdf-schema#label> ?label. }";
        ResultSet results = null;
        QueryExecution qexec = null;

        final com.hp.hpl.jena.query.Query cquery = QueryFactory.create(query);
        qexec = QueryExecutionFactory.create(cquery, this.labelmodel);
        results = qexec.execSelect();

        if (results != null) {
            while (results.hasNext()) {
                final QuerySolution sol = results.nextSolution();
                final String label = sol.getLiteral("label").getLexicalForm();
                labellist.add(label);
            }
            qexec.close();
        }
    } catch (QueryParseException e) {
        Logger.getRootLogger().info("Query parse Exception");
    }
    return labellist;
}
项目:DoSeR    文件:CreateDBpediaIndexV2.java   
public String getDbPediaShortDescription(final String uri) throws QueryException, QueryParseException {
    String labellist = "";
    try {
        final String query = "SELECT ?comment WHERE{ <" + uri
                + "> <http://www.w3.org/2000/01/rdf-schema#comment> ?comment. }";
        ResultSet results = null;
        QueryExecution qexec = null;

        final com.hp.hpl.jena.query.Query cquery = QueryFactory.create(query);
        qexec = QueryExecutionFactory.create(cquery, this.shortdescmodel);
        results = qexec.execSelect();

        if (results != null) {
            while (results.hasNext()) {
                final QuerySolution sol = results.nextSolution();
                String desc = sol.getLiteral("comment").getLexicalForm();
                labellist = desc;
            }
            qexec.close();
        }
    } catch (QueryParseException e) {
        Logger.getRootLogger().info("Query parse Exception");
    }
    return labellist;
}
项目:DoSeR    文件:CreateDBpediaIndexV2.java   
public String getDbPediaLongDescription(final String uri) throws QueryException, QueryParseException {
    String labellist = "";
    try {
        final String query = "SELECT ?comment WHERE{ <" + uri
                + "> <http://dbpedia.org/ontology/abstract> ?comment. }";
        ResultSet results = null;
        QueryExecution qexec = null;

        final com.hp.hpl.jena.query.Query cquery = QueryFactory.create(query);
        qexec = QueryExecutionFactory.create(cquery, this.longdescmodel);
        results = qexec.execSelect();

        if (results != null) {
            while (results.hasNext()) {
                final QuerySolution sol = results.nextSolution();
                final String desc = sol.getLiteral("comment").getLexicalForm();
                labellist = desc;
            }
            qexec.close();
        }
    } catch (QueryParseException e) {
        Logger.getRootLogger().info("Query parse Exception");
    }
    return labellist;
}
项目:DoSeR    文件:CreateDBpediaIndexV2.java   
public Set<String> getRDFTypesFromEntity(final String entityUri) {
    Set<String> set = new HashSet<String>();
    final String query = "SELECT ?types WHERE{ <" + entityUri
            + "> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?types. }";
    ResultSet results = null;
    QueryExecution qexec = null;
    try {
        final com.hp.hpl.jena.query.Query cquery = QueryFactory.create(query);
        qexec = QueryExecutionFactory.create(cquery, instancemappingtypes);
        results = qexec.execSelect();
    } catch (final QueryException e) {
        Logger.getRootLogger().error(e.getStackTrace());
    } finally {
        if (results != null) {
            while (results.hasNext()) {
                final QuerySolution sol = results.nextSolution();
                final String type = sol.getResource("types").toString();
                set.add(type);
            }
        }
    }
    return set;
}
项目:DoSeR    文件:DBpediaCategoryCorrection.java   
public Set<String> querySubCategories(final String uri) {
    final Set<String> types = new HashSet<String>();
    final String query = "SELECT ?sub WHERE { <"+uri+"> <http://www.w3.org/2004/02/skos/core#broader> ?sub }";

    try {
        final com.hp.hpl.jena.query.Query que = QueryFactory.create(query);
        final QueryExecution qexec = QueryExecutionFactory.create(que,
                categorySkosModel);
        final ResultSet results = qexec.execSelect();

        while (results.hasNext()) {
            final QuerySolution sol = results.nextSolution();
            final String name = sol.getResource("sub").toString();
            types.add(new String(name));
        }
    } catch (final QueryException e) {
        Logger.getRootLogger().error(e.getStackTrace());
    }
    return types;
}