Java Code Examples for org.eclipse.rdf4j.model.vocabulary.RDFS#NAMESPACE

The following examples show how to use org.eclipse.rdf4j.model.vocabulary.RDFS#NAMESPACE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RdfCloudTripleStoreConnectionTest.java    From rya with Apache License 2.0 5 votes vote down vote up
public void testEquivPropOf() throws Exception {
      if(internalInferenceEngine == null)
 {
	return; //infer not supported;
}

      RepositoryConnection conn = repository.getConnection();
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "undergradDegreeFrom"), OWL.EQUIVALENTPROPERTY, VF.createIRI(litdupsNS, "ugradDegreeFrom")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "UgradA"), VF.createIRI(litdupsNS, "undergradDegreeFrom"), VF.createIRI(litdupsNS, "Harvard")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "GradB"), VF.createIRI(litdupsNS, "ugradDegreeFrom"), VF.createIRI(litdupsNS, "Harvard")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "GradC"), VF.createIRI(litdupsNS, "ugraduateDegreeFrom"), VF.createIRI(litdupsNS, "Harvard")));
      conn.commit();
      conn.close();

      internalInferenceEngine.refreshGraph();

      conn = repository.getConnection();

      String query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select * where {?s lit:ugradDegreeFrom lit:Harvard.}";

      TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      CountTupleHandler tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(2, tupleHandler.getCount());

      conn.close();
  }
 
Example 2
Source File: RdfCloudTripleStoreConnectionTest.java    From rya with Apache License 2.0 5 votes vote down vote up
public void testInverseOf() throws Exception {
      if(internalInferenceEngine == null)
 {
	return; //infer not supported;
}

      RepositoryConnection conn = repository.getConnection();
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "degreeFrom"), OWL.INVERSEOF, VF.createIRI(litdupsNS, "hasAlumnus")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "UgradA"), VF.createIRI(litdupsNS, "degreeFrom"), VF.createIRI(litdupsNS, "Harvard")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "GradB"), VF.createIRI(litdupsNS, "degreeFrom"), VF.createIRI(litdupsNS, "Harvard")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "Harvard"), VF.createIRI(litdupsNS, "hasAlumnus"), VF.createIRI(litdupsNS, "AlumC")));
      conn.commit();
      conn.close();

      internalInferenceEngine.refreshGraph();

      conn = repository.getConnection();

      String query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select * where {lit:Harvard lit:hasAlumnus ?s.}";

      TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      CountTupleHandler tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(3, tupleHandler.getCount());

      query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select * where {?s lit:degreeFrom lit:Harvard.}";

      tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(3, tupleHandler.getCount());

      conn.close();
  }
 
Example 3
Source File: RdfCloudTripleStoreConnectionTest.java    From rya with Apache License 2.0 4 votes vote down vote up
public void testSubPropertyOf() throws Exception {
      if(internalInferenceEngine == null)
 {
	return; //infer not supported;
}

      RepositoryConnection conn = repository.getConnection();
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "undergradDegreeFrom"), RDFS.SUBPROPERTYOF, VF.createIRI(litdupsNS, "degreeFrom")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "gradDegreeFrom"), RDFS.SUBPROPERTYOF, VF.createIRI(litdupsNS, "degreeFrom")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "degreeFrom"), RDFS.SUBPROPERTYOF, VF.createIRI(litdupsNS, "memberOf")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "memberOf"), RDFS.SUBPROPERTYOF, VF.createIRI(litdupsNS, "associatedWith")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "UgradA"), VF.createIRI(litdupsNS, "undergradDegreeFrom"), VF.createIRI(litdupsNS, "Harvard")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "GradB"), VF.createIRI(litdupsNS, "gradDegreeFrom"), VF.createIRI(litdupsNS, "Yale")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "ProfessorC"), VF.createIRI(litdupsNS, "memberOf"), VF.createIRI(litdupsNS, "Harvard")));
      conn.commit();
      conn.close();

      internalInferenceEngine.refreshGraph();

      conn = repository.getConnection();

      String query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select * where {?s lit:degreeFrom lit:Harvard.}";

      TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      CountTupleHandler tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(1, tupleHandler.getCount());

      query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select * where {?s lit:memberOf lit:Harvard.}";

      tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(2, tupleHandler.getCount());

      query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select * where {?s lit:associatedWith ?o.}";

      tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(3, tupleHandler.getCount());

      query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select * where {?s lit:gradDegreeFrom lit:Yale.}";

      tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(1, tupleHandler.getCount());

      conn.close();
  }
 
Example 4
Source File: RdfCloudTripleStoreConnectionTest.java    From rya with Apache License 2.0 4 votes vote down vote up
public void testSymmPropOf() throws Exception {
      if(internalInferenceEngine == null)
 {
	return; //infer not supported;
}

      RepositoryConnection conn = repository.getConnection();
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "friendOf"), RDF.TYPE, OWL.SYMMETRICPROPERTY));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "Bob"), VF.createIRI(litdupsNS, "friendOf"), VF.createIRI(litdupsNS, "Jeff")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "James"), VF.createIRI(litdupsNS, "friendOf"), VF.createIRI(litdupsNS, "Jeff")));
      conn.commit();
      conn.close();

      internalInferenceEngine.refreshGraph();

      conn = repository.getConnection();

      String query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select * where {?s lit:friendOf lit:Bob.}";

      TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      CountTupleHandler tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(1, tupleHandler.getCount());

      query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select * where {?s lit:friendOf lit:James.}";

      tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(1, tupleHandler.getCount());

      query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select * where {?s lit:friendOf lit:Jeff.}";

      tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(2, tupleHandler.getCount());

      conn.close();
  }
 
Example 5
Source File: RdfCloudTripleStoreConnectionTest.java    From rya with Apache License 2.0 4 votes vote down vote up
public void testTransitiveProp() throws Exception {
      if(internalInferenceEngine == null)
 {
	return; //infer not supported;
}

      RepositoryConnection conn = repository.getConnection();
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "subRegionOf"), RDF.TYPE, OWL.TRANSITIVEPROPERTY));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "Queens"), VF.createIRI(litdupsNS, "subRegionOf"), VF.createIRI(litdupsNS, "NYC")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "NYC"), VF.createIRI(litdupsNS, "subRegionOf"), VF.createIRI(litdupsNS, "NY")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "NY"), VF.createIRI(litdupsNS, "subRegionOf"), VF.createIRI(litdupsNS, "US")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "US"), VF.createIRI(litdupsNS, "subRegionOf"), VF.createIRI(litdupsNS, "NorthAmerica")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "NorthAmerica"), VF.createIRI(litdupsNS, "subRegionOf"), VF.createIRI(litdupsNS, "World")));
      conn.commit();
      conn.close();

      internalInferenceEngine.refreshGraph();

      conn = repository.getConnection();

      String query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select * where {?s lit:subRegionOf lit:NorthAmerica.}";

      TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      CountTupleHandler tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(4, tupleHandler.getCount());

      query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select * where {?s lit:subRegionOf lit:NY.}";

      tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(2, tupleHandler.getCount());

      query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select * where {lit:Queens lit:subRegionOf ?s.}";

      tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(5, tupleHandler.getCount());

      query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select * where {lit:NY lit:subRegionOf ?s.}";

      tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(3, tupleHandler.getCount());

      conn.close();
  }
 
Example 6
Source File: RdfCloudTripleStoreConnectionTest.java    From rya with Apache License 2.0 4 votes vote down vote up
public void testSubClassOf() throws Exception {
      if(internalInferenceEngine == null)
 {
	return; //infer not supported;
}

      RepositoryConnection conn = repository.getConnection();
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "UndergraduateStudent"), RDFS.SUBCLASSOF, VF.createIRI(litdupsNS, "Student")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "Student"), RDFS.SUBCLASSOF, VF.createIRI(litdupsNS, "Person")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "UgradA"), RDF.TYPE, VF.createIRI(litdupsNS, "UndergraduateStudent")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "StudentB"), RDF.TYPE, VF.createIRI(litdupsNS, "Student")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "PersonC"), RDF.TYPE, VF.createIRI(litdupsNS, "Person")));
      conn.commit();
      conn.close();

      internalInferenceEngine.refreshGraph();

      conn = repository.getConnection();

      //simple api first
      RepositoryResult<Statement> person = conn.getStatements(null, RDF.TYPE, VF.createIRI(litdupsNS, "Person"), true);
      int count = 0;
      while (person.hasNext()) {
          count++;
          person.next();
      }
      person.close();
      assertEquals(3, count);

      String query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select * where {?s rdf:type lit:Person.}";

      TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      CountTupleHandler tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(3, tupleHandler.getCount());

      query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select * where {?s rdf:type lit:Student.}";

      tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(2, tupleHandler.getCount());

      query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select * where {?s rdf:type lit:UndergraduateStudent.}";

      tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(1, tupleHandler.getCount());

      conn.close();
  }
 
Example 7
Source File: RdfCloudTripleStoreConnectionTest.java    From rya with Apache License 2.0 4 votes vote down vote up
public void testSameAs() throws Exception {
      if(internalInferenceEngine == null)
 {
	return; //infer not supported;
}

      RepositoryConnection conn = repository.getConnection();
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "StudentA1"), OWL.SAMEAS, VF.createIRI(litdupsNS, "StudentA2")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "StudentA2"), OWL.SAMEAS, VF.createIRI(litdupsNS, "StudentA3")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "StudentB1"), OWL.SAMEAS, VF.createIRI(litdupsNS, "StudentB2")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "StudentB2"), OWL.SAMEAS, VF.createIRI(litdupsNS, "StudentB3")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "StudentA1"), VF.createIRI(litdupsNS, "pred1"), VF.createIRI(litdupsNS, "StudentB3")));
      conn.add(VF.createStatement(VF.createIRI(litdupsNS, "StudentB1"), VF.createIRI(litdupsNS, "pred2"), VF.createIRI(litdupsNS, "StudentA3")));
      conn.commit();
      conn.close();

      internalInferenceEngine.refreshGraph();

      conn = repository.getConnection();

      // query where finds sameAs for obj, pred specified
      String query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select ?s where {?s lit:pred1 lit:StudentB2.}";

      TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      CountTupleHandler tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(1, tupleHandler.getCount());

      // query where finds sameAs for obj only specified
      query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select ?s where {?s ?p lit:StudentB2.}";

      tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(3, tupleHandler.getCount()); // including sameAs assertions

      // query where finds sameAs for subj, pred specified
      query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select ?s where {lit:StudentB2 lit:pred2 ?s.}";

      tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(1, tupleHandler.getCount()); // including sameAs assertions

      // query where finds sameAs for subj only specified
      query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select ?s where {lit:StudentB2 ?p ?s.}";

      tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(3, tupleHandler.getCount()); // including sameAs assertions

      // query where finds sameAs for subj, obj specified
      query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" +
              "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" +
              "PREFIX lit: <" + litdupsNS + ">\n" +
              "select ?s where {lit:StudentB2 ?s lit:StudentA2.}";

      tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      tupleHandler = new CountTupleHandler();
      tupleQuery.evaluate(tupleHandler);
      assertEquals(1, tupleHandler.getCount());

      conn.close();
  }
 
Example 8
Source File: InferenceExamples.java    From rya with Apache License 2.0 4 votes vote down vote up
public static void testSomeValuesFromInference(final SailRepositoryConnection conn, final Sail sail) throws MalformedQueryException, RepositoryException,
UpdateExecutionException, QueryEvaluationException, TupleQueryResultHandlerException, InferenceEngineException {
    final String lubm = "http://swat.cse.lehigh.edu/onto/univ-bench.owl#";
    log.info("Adding Data");
    String insert = "PREFIX lubm: <" + lubm + ">\n"
            + "INSERT DATA { GRAPH <http://updated/test> {\n"
            + "  <urn:Department0> a lubm:Department; lubm:subOrganizationOf <urn:University0> .\n"
            + "  <urn:ResearchGroup0> a lubm:ResearchGroup; lubm:subOrganizationOf <urn:Department0> .\n"
            + "  <urn:Alice> lubm:headOf <urn:Department0> .\n"
            + "  <urn:Bob> lubm:headOf <urn:ResearchGroup0> .\n"
            + "  <urn:Carol> lubm:worksFor <urn:Department0> .\n"
            + "}}";
    Update update = conn.prepareUpdate(QueryLanguage.SPARQL, insert);
    update.execute();
    final String inferQuery = "select distinct ?x { GRAPH <http://updated/test> { ?x a <" + lubm + "Chair> }}";
    final String explicitQuery = "prefix lubm: <" + lubm + ">\n"
            + "select distinct ?x { GRAPH <http://updated/test> {\n"
            + "  { ?x a lubm:Chair }\n"
            + "  UNION\n"
            + "  { ?x lubm:headOf [ a lubm:Department ] }\n"
            + "}}";
    log.info("Running Explicit Query");
    final CountingResultHandler resultHandler = new CountingResultHandler();
    TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, explicitQuery);
    tupleQuery.evaluate(resultHandler);
    log.info("Result count : " + resultHandler.getCount());
    Validate.isTrue(resultHandler.getCount() == 1);
    log.info("Running Inference-dependent Query");
    resultHandler.resetCount();
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, inferQuery);
    tupleQuery.evaluate(resultHandler);
    log.info("Result count : " + resultHandler.getCount());
    Validate.isTrue(resultHandler.getCount() == 0);
    log.info("Adding owl:someValuesFrom Schema");
    insert = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n"
            + "PREFIX owl: <" + OWL.NAMESPACE + ">\n"
            + "PREFIX lubm: <" + lubm + ">\n"
            + "INSERT DATA\n"
            + "{ GRAPH <http://updated/test> {\n"
            + "  lubm:Chair owl:equivalentClass [ owl:onProperty lubm:headOf ; owl:someValuesFrom lubm:Department ] ."
            + "}}";
    update = conn.prepareUpdate(QueryLanguage.SPARQL, insert);
    update.execute();
    log.info("Refreshing InferenceEngine");
    ((RdfCloudTripleStore<?>) sail).getInferenceEngine().refreshGraph();
    log.info("Re-running Inference-dependent Query");
    resultHandler.resetCount();
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, inferQuery);
    tupleQuery.evaluate(resultHandler);
    log.info("Result count : " + resultHandler.getCount());
    Validate.isTrue(resultHandler.getCount() == 1);
}
 
Example 9
Source File: InferenceExamples.java    From rya with Apache License 2.0 4 votes vote down vote up
public static void testAllValuesFromInference(final SailRepositoryConnection conn, final Sail sail) throws MalformedQueryException, RepositoryException,
UpdateExecutionException, QueryEvaluationException, TupleQueryResultHandlerException, InferenceEngineException {
    log.info("Adding Data");
    String insert = "INSERT DATA\n"
            + "{ GRAPH <http://updated/test> {\n"
            + "  <urn:Alice> a <urn:Person> .\n"
            + "  <urn:Alice> <urn:hasParent> <urn:Bob> .\n"
            + "  <urn:Carol> <urn:hasParent> <urn:Dan> .\n"
            + "}}";
    Update update = conn.prepareUpdate(QueryLanguage.SPARQL, insert);
    update.execute();
    final String inferQuery = "select distinct ?x { GRAPH <http://updated/test> { ?x a <urn:Person> }}";
    final String explicitQuery = "select distinct ?x { GRAPH <http://updated/test> {\n"
            + "  { ?x a <urn:Person> }\n"
            + "  UNION {\n"
            + "    ?y a <urn:Person> .\n"
            + "    ?y <urn:hasParent> ?x .\n"
            + "  }\n"
            + "}}";
    log.info("Running Explicit Query");
    final CountingResultHandler resultHandler = new CountingResultHandler();
    TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, explicitQuery);
    tupleQuery.evaluate(resultHandler);
    log.info("Result count : " + resultHandler.getCount());
    Validate.isTrue(resultHandler.getCount() == 2);
    log.info("Running Inference-dependent Query");
    resultHandler.resetCount();
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, inferQuery);
    tupleQuery.evaluate(resultHandler);
    log.info("Result count : " + resultHandler.getCount());
    Validate.isTrue(resultHandler.getCount() == 1);
    log.info("Adding owl:allValuesFrom Schema");
    insert = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n"
            + "PREFIX owl: <" + OWL.NAMESPACE + ">\n"
            + "INSERT DATA\n"
            + "{ GRAPH <http://updated/test> {\n"
            + "  <urn:Person> rdfs:subClassOf [ owl:onProperty <urn:hasParent> ; owl:allValuesFrom <urn:Person> ] ."
            + "}}";
    update = conn.prepareUpdate(QueryLanguage.SPARQL, insert);
    update.execute();
    log.info("Refreshing InferenceEngine");
    ((RdfCloudTripleStore<?>) sail).getInferenceEngine().refreshGraph();
    log.info("Re-running Inference-dependent Query");
    resultHandler.resetCount();
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, inferQuery);
    tupleQuery.evaluate(resultHandler);
    log.info("Result count : " + resultHandler.getCount());
    Validate.isTrue(resultHandler.getCount() == 2);
}
 
Example 10
Source File: MongoRyaDirectExample.java    From rya with Apache License 2.0 4 votes vote down vote up
public static void testSomeValuesFromInference(final SailRepositoryConnection conn, final Sail sail) throws MalformedQueryException, RepositoryException,
UpdateExecutionException, QueryEvaluationException, TupleQueryResultHandlerException, InferenceEngineException {
    final String lubm = "http://swat.cse.lehigh.edu/onto/univ-bench.owl#";
    log.info("Adding Data");
    String insert = "PREFIX lubm: <" + lubm + ">\n"
            + "INSERT DATA { GRAPH <http://updated/test> {\n"
            + "  <urn:Department0> a lubm:Department; lubm:subOrganizationOf <urn:University0> .\n"
            + "  <urn:ResearchGroup0> a lubm:ResearchGroup; lubm:subOrganizationOf <urn:Department0> .\n"
            + "  <urn:Alice> lubm:headOf <urn:Department0> .\n"
            + "  <urn:Bob> lubm:headOf <urn:ResearchGroup0> .\n"
            + "  <urn:Carol> lubm:worksFor <urn:Department0> .\n"
            + "}}";
    Update update = conn.prepareUpdate(QueryLanguage.SPARQL, insert);
    update.execute();
    final String inferQuery = "select distinct ?x { GRAPH <http://updated/test> { ?x a <" + lubm + "Chair> }}";
    final String explicitQuery = "prefix lubm: <" + lubm + ">\n"
            + "select distinct ?x { GRAPH <http://updated/test> {\n"
            + "  { ?x a lubm:Chair }\n"
            + "  UNION\n"
            + "  { ?x lubm:headOf [ a lubm:Department ] }\n"
            + "}}";
    log.info("Running Explicit Query");
    final CountingResultHandler resultHandler = new CountingResultHandler();
    TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, explicitQuery);
    tupleQuery.evaluate(resultHandler);
    log.info("Result count : " + resultHandler.getCount());
    Validate.isTrue(resultHandler.getCount() == 1);
    log.info("Running Inference-dependent Query");
    resultHandler.resetCount();
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, inferQuery);
    tupleQuery.evaluate(resultHandler);
    log.info("Result count : " + resultHandler.getCount());
    Validate.isTrue(resultHandler.getCount() == 0);
    log.info("Adding owl:someValuesFrom Schema");
    insert = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n"
            + "PREFIX owl: <" + OWL.NAMESPACE + ">\n"
            + "PREFIX lubm: <" + lubm + ">\n"
            + "INSERT DATA\n"
            + "{ GRAPH <http://updated/test> {\n"
            + "  lubm:Chair owl:equivalentClass [ owl:onProperty lubm:headOf ; owl:someValuesFrom lubm:Department ] ."
            + "}}";
    update = conn.prepareUpdate(QueryLanguage.SPARQL, insert);
    update.execute();
    log.info("Refreshing InferenceEngine");
    ((RdfCloudTripleStore<?>) sail).getInferenceEngine().refreshGraph();
    log.info("Re-running Inference-dependent Query");
    resultHandler.resetCount();
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, inferQuery);
    tupleQuery.evaluate(resultHandler);
    log.info("Result count : " + resultHandler.getCount());
    Validate.isTrue(resultHandler.getCount() == 1);
}
 
Example 11
Source File: MongoRyaDirectExample.java    From rya with Apache License 2.0 4 votes vote down vote up
public static void testAllValuesFromInference(final SailRepositoryConnection conn, final Sail sail) throws MalformedQueryException, RepositoryException,
UpdateExecutionException, QueryEvaluationException, TupleQueryResultHandlerException, InferenceEngineException {
    log.info("Adding Data");
    String insert = "INSERT DATA\n"
            + "{ GRAPH <http://updated/test> {\n"
            + "  <urn:Alice> a <urn:Person> .\n"
            + "  <urn:Alice> <urn:hasParent> <urn:Bob> .\n"
            + "  <urn:Carol> <urn:hasParent> <urn:Dan> .\n"
            + "}}";
    Update update = conn.prepareUpdate(QueryLanguage.SPARQL, insert);
    update.execute();
    final String inferQuery = "select distinct ?x { GRAPH <http://updated/test> { ?x a <urn:Person> }}";
    final String explicitQuery = "select distinct ?x { GRAPH <http://updated/test> {\n"
            + "  { ?x a <urn:Person> }\n"
            + "  UNION {\n"
            + "    ?y a <urn:Person> .\n"
            + "    ?y <urn:hasParent> ?x .\n"
            + "  }\n"
            + "}}";
    log.info("Running Explicit Query");
    final CountingResultHandler resultHandler = new CountingResultHandler();
    TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, explicitQuery);
    tupleQuery.evaluate(resultHandler);
    log.info("Result count : " + resultHandler.getCount());
    Validate.isTrue(resultHandler.getCount() == 2);
    log.info("Running Inference-dependent Query");
    resultHandler.resetCount();
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, inferQuery);
    tupleQuery.evaluate(resultHandler);
    log.info("Result count : " + resultHandler.getCount());
    Validate.isTrue(resultHandler.getCount() == 1);
    log.info("Adding owl:allValuesFrom Schema");
    insert = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n"
            + "PREFIX owl: <" + OWL.NAMESPACE + ">\n"
            + "INSERT DATA\n"
            + "{ GRAPH <http://updated/test> {\n"
            + "  <urn:Person> rdfs:subClassOf [ owl:onProperty <urn:hasParent> ; owl:allValuesFrom <urn:Person> ] ."
            + "}}";
    update = conn.prepareUpdate(QueryLanguage.SPARQL, insert);
    update.execute();
    log.info("Refreshing InferenceEngine");
    ((RdfCloudTripleStore<?>) sail).getInferenceEngine().refreshGraph();
    log.info("Re-running Inference-dependent Query");
    resultHandler.resetCount();
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, inferQuery);
    tupleQuery.evaluate(resultHandler);
    log.info("Result count : " + resultHandler.getCount());
    Validate.isTrue(resultHandler.getCount() == 2);
}