org.openrdf.model.vocabulary.RDFS Java Examples

The following examples show how to use org.openrdf.model.vocabulary.RDFS. 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: SPARQLUpdateTest.java    From database with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testInsertWhereWithBinding()
	throws Exception
{
	logger.debug("executing test testInsertWhereWithBinding");
	StringBuilder update = new StringBuilder();
	update.append(getNamespaceDeclarations());
	update.append("INSERT {?x rdfs:label ?y . } WHERE {?x foaf:name ?y }");

	Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
	operation.setBinding("x", bob);

	assertFalse(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
	assertFalse(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));

	operation.execute();

	assertTrue(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
	assertFalse(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
}
 
Example #2
Source File: SPARQLUpdateTest.java    From database with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testInsertTransformedWhere()
	throws Exception
{
	logger.debug("executing test InsertTransformedWhere");

	StringBuilder update = new StringBuilder();
	update.append(getNamespaceDeclarations());
	update.append("INSERT {?x rdfs:label [] . } WHERE {?y ex:containsPerson ?x.  }");

	Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());

	assertFalse(con.hasStatement(bob, RDFS.LABEL, null, true));
	assertFalse(con.hasStatement(alice, RDFS.LABEL, null, true));

	operation.execute();

	assertTrue(con.hasStatement(bob, RDFS.LABEL, null, true));
	assertTrue(con.hasStatement(alice, RDFS.LABEL, null, true));
}
 
Example #3
Source File: SPARQLUpdateTest.java    From database with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testInsertEmptyWhere()
	throws Exception
{
	logger.debug("executing test testInsertEmptyWhere");
	StringBuilder update = new StringBuilder();
	update.append(getNamespaceDeclarations());
	update.append("INSERT { <" + bob + "> rdfs:label \"Bob\" . } WHERE { }");

	Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());

	assertFalse(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));

	operation.execute();

	assertTrue(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
}
 
Example #4
Source File: SPARQLUpdateTest.java    From database with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDeleteInsertWhere()
	throws Exception
{
	logger.debug("executing test DeleteInsertWhere");
	StringBuilder update = new StringBuilder();
	update.append(getNamespaceDeclarations());
	update.append("DELETE { ?x foaf:name ?y } INSERT {?x rdfs:label ?y . } WHERE {?x foaf:name ?y }");

	Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());

	assertFalse(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
	assertFalse(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));

	operation.execute();

	assertTrue(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
	assertTrue(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));

	assertFalse(con.hasStatement(bob, FOAF.NAME, f.createLiteral("Bob"), true));
	assertFalse(con.hasStatement(alice, FOAF.NAME, f.createLiteral("Alice"), true));

}
 
Example #5
Source File: SPARQLUpdateTest.java    From database with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testInsertWhereWithBindings()
	throws Exception
{
	logger.debug("executing test testInsertWhereWithBindings");
	StringBuilder update = new StringBuilder();
	update.append(getNamespaceDeclarations());
	update.append("INSERT { ?x rdfs:comment ?z . } WHERE { ?x foaf:name ?y }");

	Literal comment = f.createLiteral("Bob has a comment");

	Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
	operation.setBinding("x", bob);
	operation.setBinding("z", comment);

	assertFalse(con.hasStatement(null, RDFS.COMMENT, comment, true));

	operation.execute();

	assertTrue(con.hasStatement(bob, RDFS.COMMENT, comment, true));
	assertFalse(con.hasStatement(alice, RDFS.COMMENT, comment, true));

}
 
Example #6
Source File: SPARQLUpdateTest.java    From database with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testInsertWhereGraph()
	throws Exception
{
	logger.debug("executing testInsertWhereGraph");
	StringBuilder update = new StringBuilder();
	update.append(getNamespaceDeclarations());
	update.append("INSERT {GRAPH ?g {?x rdfs:label ?y . }} WHERE {GRAPH ?g {?x foaf:name ?y }}");

	Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());

	operation.execute();

	String message = "labels should have been inserted in corresponding named graphs only.";
	assertTrue(message, con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true, graph1));
	assertFalse(message, con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true, graph2));
	assertTrue(message, con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true, graph2));
	assertFalse(message, con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true, graph1));
}
 
Example #7
Source File: QueryService.java    From anno4j with Apache License 2.0 6 votes vote down vote up
public <T> QueryService(ObjectConnection connection, LDPathEvaluatorConfiguration evaluatorConfiguration) {
    this.connection = connection;

    this.queryServiceDTO = new QueryServiceConfiguration();
    queryServiceDTO.setEvaluatorConfiguration(evaluatorConfiguration);
    queryServiceDTO.setConfiguration(createLDPathConfiguration());

    this.queryOptimizer = QueryOptimizer.getInstance();

    // Setting some common name spaces
    addPrefix(OADM.PREFIX, OADM.NS);
    addPrefix(CNT.PREFIX, CNT.NS);
    addPrefix(DC.PREFIX, DC.NS);
    addPrefix(DCTERMS.PREFIX, DCTERMS.NS);
    addPrefix(DCTYPES.PREFIX, DCTYPES.NS);
    addPrefix(FOAF.PREFIX, FOAF.NS);
    addPrefix(PROV.PREFIX, PROV.NS);
    addPrefix(RDF.PREFIX, RDF.NS);
    addPrefix(OWL.PREFIX, OWL.NAMESPACE);
    addPrefix(RDFS.PREFIX, RDFS.NAMESPACE);
    addPrefix(SKOS.PREFIX, SKOS.NAMESPACE);
}
 
Example #8
Source File: AbstractTestNanoSparqlClient.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
* Sets up a simple data set on the server.
* 
* @throws Exception
*/
protected void setupDataOnServer() throws Exception {
    
    final URI mike = new URIImpl(BD.NAMESPACE + "Mike");
    final URI bryan = new URIImpl(BD.NAMESPACE + "Bryan");
    final URI person = new URIImpl(BD.NAMESPACE + "Person");
    final URI likes = new URIImpl(BD.NAMESPACE + "likes");
    final URI rdf = new URIImpl(BD.NAMESPACE + "RDF");
    final URI rdfs = new URIImpl(BD.NAMESPACE + "RDFS");
    final Literal label1 = new LiteralImpl("Mike");
    final Literal label2 = new LiteralImpl("Bryan");

  {
     final Graph g = new LinkedHashModel();
     g.add(mike, RDF.TYPE, person);
     g.add(mike, likes, rdf);
     g.add(mike, RDFS.LABEL, label1);
     g.add(bryan, RDF.TYPE, person);
     g.add(bryan, likes, rdfs);
     g.add(bryan, RDFS.LABEL, label2);

     m_repo.add(new AddOp(g));
  }

}
 
Example #9
Source File: SPARQLUpdateTest.java    From database with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testInsertWhereWithBindings2()
	throws Exception
{
	logger.debug("executing test testInsertWhereWithBindings2");
	StringBuilder update = new StringBuilder();
	update.append(getNamespaceDeclarations());
	update.append("INSERT {?x rdfs:label ?z . } WHERE {?x foaf:name ?y }");

	Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
	operation.setBinding("z", f.createLiteral("Bobbie"));
	operation.setBinding("x", bob);

	assertFalse(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bobbie"), true));
	assertFalse(con.hasStatement(alice, RDFS.LABEL, null, true));

	operation.execute();

	assertTrue(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bobbie"), true));
	assertFalse(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
}
 
Example #10
Source File: ForwardChainingRDFSInferencerConnection.java    From semweb4j with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private int applyRuleRdfs10()
	throws SailException
{
	int nofInferred = 0;

	Iterator<Statement> iter = this.newThisIteration.match(null, RDF.TYPE, RDFS.CLASS);

	while (iter.hasNext()) {
		Statement st = iter.next();

		Resource xxx = st.getSubject();

		boolean added = addInferredStatement(xxx, RDFS.SUBCLASSOF, xxx);
		if (added) {
			nofInferred++;
		}
	}

	return nofInferred;
}
 
Example #11
Source File: TestSparqlUpdate.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/** @since OPENRDF 2.6.3 */
//  @Test
    public void testInsertDataInGraph2()
      throws Exception
    {
      log.debug("executing testInsertDataInGraph2");

      final StringBuilder update = new StringBuilder();
      update.append(getNamespaceDeclarations());
      update.append("INSERT DATA { GRAPH ex:graph1 { ex:Human rdfs:subClassOf ex:Mammal. ex:Mammal rdfs:subClassOf ex:Animal. ex:george a ex:Human. ex:ringo a ex:Human. } } ");

      final URI human = f.createURI(EX_NS, "Human");
      final URI mammal = f.createURI(EX_NS, "Mammal");
      final URI george = f.createURI(EX_NS, "george");

      m_repo.prepareUpdate(update.toString()).evaluate();

      assertTrue(hasStatement(human, RDFS.SUBCLASSOF, mammal, true, graph1));
      assertTrue(hasStatement(mammal, RDFS.SUBCLASSOF, null, true, graph1));
      assertTrue(hasStatement(george, RDF.TYPE, human, true, graph1));
    }
 
Example #12
Source File: RDFClass.java    From anno4j with Apache License 2.0 6 votes vote down vote up
public boolean isMinCardinality(RDFProperty property) {
	BigInteger one = BigInteger.valueOf(1);
	for (RDFClass c : getRDFClasses(RDFS.SUBCLASSOF)) {
		if (c.isA(OWL.RESTRICTION)) {
			if (property.equals(c.getRDFProperty(OWL.ONPROPERTY))) {
				if (one.equals(c.getBigInteger(OWL.MAXCARDINALITY))
						&& one.equals(c.getBigInteger(OWL.MINCARDINALITY))
						|| one.equals(c.getBigInteger(OWL.CARDINALITY))) {
					return true;
				}
			}
		} else if (equals(c)) {
			continue;
		} else if (c.isMinCardinality(property)) {
			return true;
		}
	}
	return false;
}
 
Example #13
Source File: RDFClass.java    From anno4j with Apache License 2.0 6 votes vote down vote up
public Collection<RDFClass> getDeclaredMessages() {
	Set<RDFClass> set = new TreeSet<RDFClass>();
	for (Resource res : model.filter(null, OWL.ALLVALUESFROM, self)
			.subjects()) {
		if (model.contains(res, OWL.ONPROPERTY, MSG.TARGET)) {
			for (Resource msg : model.filter(null, RDFS.SUBCLASSOF, res)
					.subjects()) {
				if (MSG.MESSAGE.equals(msg))
					continue;
				RDFClass rc = new RDFClass(model, msg);
				if (rc.isMessageClass()) {
					set.add(rc);
				}
			}
		}
	}
	return set;
}
 
Example #14
Source File: RDFClass.java    From anno4j with Apache License 2.0 6 votes vote down vote up
private void interfaceHeader(JavaMessageBuilder builder)
		throws ObjectStoreConfigException {
	String pkg = builder.getPackageName(this.getURI());
	String simple = builder.getSimpleName(this.getURI());
	if (pkg == null) {
		builder.imports(simple);
	} else {
		builder.pkg(pkg);
		builder.imports(pkg + '.' + simple);
	}
	builder.comment(this);
	if (this.isA(OWL.DEPRECATEDCLASS)) {
		builder.annotate(Deprecated.class);
	}
	builder.annotationProperties(this);
	if (!builder.isAnonymous(this.getURI())) {
		builder.annotateURI(Iri.class, "value", builder.getType(this.getURI()));
	}
	builder.interfaceName(simple);
	for (RDFClass sups : this.getRDFClasses(RDFS.SUBCLASSOF)) {
		if (sups.getURI() == null || sups.equals(this))
			continue;
		builder.extend(builder.getClassName(sups.getURI()));
	}
}
 
Example #15
Source File: TestSparqlUpdate.java    From database with GNU General Public License v2.0 6 votes vote down vote up
public void testDeleteInsertWhere()
        throws Exception
    {
//        log.debug("executing test DeleteInsertWhere");
        final StringBuilder update = new StringBuilder();
        update.append(getNamespaceDeclarations());
        update.append("DELETE { ?x foaf:name ?y } INSERT {?x rdfs:label ?y . } WHERE {?x foaf:name ?y }");

        assertFalse(hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
        assertFalse(hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));

        m_repo.prepareUpdate(update.toString()).evaluate();

        assertTrue(hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
        assertTrue(hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));

        assertFalse(hasStatement(bob, FOAF.NAME, f.createLiteral("Bob"), true));
        assertFalse(hasStatement(alice, FOAF.NAME, f.createLiteral("Alice"), true));

    }
 
Example #16
Source File: TestSparqlUpdate.java    From database with GNU General Public License v2.0 6 votes vote down vote up
public void testReallyLongQueryString()
      throws Exception
  {
final Literal l = getReallyLongLiteral(1000);
    	
      log.debug("executing test testInsertEmptyWhere");
      final StringBuilder update = new StringBuilder();
      update.append(getNamespaceDeclarations());
      update.append("INSERT { <" + bob + "> rdfs:label " + l + " . } WHERE { }");

      assertFalse(hasStatement(bob, RDFS.LABEL, l, true));

      m_repo.prepareUpdate(update.toString()).evaluate();

      assertTrue(hasStatement(bob, RDFS.LABEL, l, true));
  }
 
Example #17
Source File: TestURIExtensionIV.java    From database with GNU General Public License v2.0 6 votes vote down vote up
public void test_encodeDecode_comparator() {
        
        final List<IV<?,?>> ivs = new LinkedList<IV<?,?>>();
        {

//            ivs.add(newFixture(new URIImpl("http://www.bigdata.com")));
            ivs.add(newFixture(new URIImpl("http://www.bigdata.com/")));
            ivs.add(newFixture(new URIImpl("http://www.bigdata.com/foo")));
            ivs.add(newFixture(RDFS.CLASS));
            ivs.add(newFixture(RDFS.SUBPROPERTYOF));
            ivs.add(newFixture(new URIImpl("http://www.Department0.University0.edu/UndergraduateStudent488")));
            ivs.add(newFixture(new URIImpl("http://www.Department0.University0.edu/GraduateStudent15")));
//            ivs.add(newFixture(new URIImpl("http://www.bigdata.com:80/foo")));

        }
        
        final IV<?, ?>[] e = ivs.toArray(new IV[0]);

        AbstractEncodeDecodeKeysTestCase.doEncodeDecodeTest(e);

        AbstractEncodeDecodeKeysTestCase.doComparatorTest(e);
    
    }
 
Example #18
Source File: SampleRule.java    From blazegraph-samples with GNU General Public License v2.0 6 votes vote down vote up
public SampleRule(final String relationName, final Vocabulary vocab) {

        super(  "SampleRule", // rule name
                new SPOPredicate(relationName, var("a"), var("p"), var("o")), // head
                new SPOPredicate[] { // tail
                    new SPOPredicate(relationName, var("a"), vocab.getConstant(SAMPLE.SIMILAR_TO), var("b")),
                    new SPOPredicate(relationName, var("a"), vocab.getConstant(RDF.TYPE), var("t")),
                    new SPOPredicate(relationName, var("b"), vocab.getConstant(RDF.TYPE), var("t")),
                    new SPOPredicate(relationName, var("b"), var("p"), var("o")),
                },
                new IConstraint[] { // constraints
					Constraint.wrap(new NE(var("a"), var("b"))),
        			Constraint.wrap(new NEConstant(var("t"), vocab.getConstant(RDFS.RESOURCE))),
        			// you can use SPARQL value expression bops in inference by wrapping them with an InferenceBVE
                    Constraint.wrap(new InferenceBVE(new IsLiteralBOp(
                            var("o"))))
                });

    }
 
Example #19
Source File: ForwardChainingRDFSInferencerConnection.java    From semweb4j with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private int applyRuleX1()
	throws SailException
{
	int nofInferred = 0;

	String prefix = RDF.NAMESPACE + "_";
	Iterator<Statement> iter = this.newThisIteration.match(null, null, null);

	while (iter.hasNext()) {
		Statement st = iter.next();

		URI predNode = st.getPredicate();
		String predURI = predNode.toString();

		if (predURI.startsWith(prefix) && isValidPredicateNumber(predURI.substring(prefix.length()))) {
			boolean added = addInferredStatement(predNode, RDF.TYPE, RDFS.CONTAINERMEMBERSHIPPROPERTY);
			if (added) {
				nofInferred++;
			}
		}
	}

	return nofInferred;
}
 
Example #20
Source File: ForwardChainingRDFSInferencerConnection.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private int applyRuleRdfs7_2()
	throws SailException
{
	int nofInferred = 0;

	Iterator<Statement> ntIter = this.newThisIteration.match(null, RDFS.SUBPROPERTYOF, null);

	while (ntIter.hasNext()) {
		Statement nt = ntIter.next();

		Resource aaa = nt.getSubject();
		Value bbb = nt.getObject();

		if (aaa instanceof URI && bbb instanceof URI) {
			CloseableIteration<? extends Statement, SailException> t1Iter;
			t1Iter = getWrappedConnection().getStatements(null, (URI)aaa, null, true);

			while (t1Iter.hasNext()) {
				Statement t1 = t1Iter.next();

				Resource xxx = t1.getSubject();
				Value yyy = t1.getObject();

				boolean added = addInferredStatement(xxx, (URI)bbb, yyy);
				if (added) {
					nofInferred++;
				}
			}
			t1Iter.close();
		}
	}

	return nofInferred;
}
 
Example #21
Source File: ComplexSPARQLQueryTest.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testDescribeWhere()
	throws Exception
{
	loadTestData("/testdata-query/dataset-describe.trig");
	StringBuilder query = new StringBuilder();
	query.append(getNamespaceDeclarations());
	query.append("DESCRIBE ?x WHERE {?x rdfs:label ?y . } ");

	GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString());

	ValueFactory vf = conn.getValueFactory();
	URI a = vf.createURI("http://example.org/a");
	URI b = vf.createURI("http://example.org/b");
	URI c = vf.createURI("http://example.org/c");
	URI e = vf.createURI("http://example.org/e");
	URI f = vf.createURI("http://example.org/f");
	URI p = vf.createURI("http://example.org/p");

	Model result = QueryResults.asModel(gq.evaluate());
	assertTrue(result.contains(a, p, null));
	assertTrue(result.contains(b, RDFS.LABEL, null));
	assertTrue(result.contains(c, RDFS.LABEL, null));
	assertTrue(result.contains(null, p, b));
	assertTrue(result.contains(e, RDFS.LABEL, null));
	assertTrue(result.contains(null, p, e));
	assertFalse(result.contains(f, null, null));
	Set<Value> objects = result.filter(a, p, null).objects();
	assertNotNull(objects);
	for (Value object : objects) {
		if (object instanceof BNode) {
			assertTrue(result.contains((Resource)object, null, null));
			assertEquals(2, result.filter((Resource)object, null, null).size());
		}
	}
}
 
Example #22
Source File: PrefixDeclProcessor.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
       * Provide silent declaration for some well known namspaces.
       */
      @SuppressWarnings("unused")
private String checkForWellKnownNamespacePrefix(final String prefix) {
          final String namespace;
          if (prefix.equals("bd")) {
              prefixMap.put("bd", namespace = BD.NAMESPACE);
          } else if (prefix.equals("bds")) {
              prefixMap.put("bds", namespace = BDS.NAMESPACE);
          } else if (prefix.equals("hint")) {
              prefixMap.put("hint", namespace = QueryHints.NAMESPACE);
          } else if (prefix.equals("rdf")) {
              prefixMap.put("rdf", namespace = RDF.NAMESPACE);
          } else if (prefix.equals("rdfs")) {
              prefixMap.put("rdfs", namespace = RDFS.NAMESPACE);
          } else if (prefix.equals("xsd")) {
              prefixMap.put("xsd", namespace = XSD.NAMESPACE);
          } else if (prefix.equals("foaf")) {
              prefixMap.put("foaf", namespace = FOAFVocabularyDecl.NAMESPACE);
          } else if (prefix.equals("fn")) { // XPath Functions.
              prefixMap.put("fn", namespace = FN.NAMESPACE);
          } else if (prefix.equals("owl")) {
              prefixMap.put("owl", namespace = OWL.NAMESPACE);
          } else if (prefix.equals("sesame")) {
              prefixMap.put("sesame", namespace = SESAME.NAMESPACE);
          } else if (prefix.equals("gas")) {
              prefixMap.put("gas", namespace = GASService.Options.NAMESPACE);
          } else {
              // Unknown
              namespace = null;
          }
          return namespace;
      }
 
Example #23
Source File: RuleFastClosure9.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public RuleFastClosure9(String database, String focusStore, Vocabulary vocab) {
    //, Set<Long> T
    
    super("fastClosure9",database,focusStore,//
            vocab.getConstant(RDFS.SUBPROPERTYOF),//
            vocab.getConstant(RDF.TYPE)//
            );
    //, T);
    
}
 
Example #24
Source File: RuleRdfs04a.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public RuleRdfs04a(String relationName,Vocabulary vocab) {

            super(  "rdfs04a",//
                    new SPOPredicate(relationName,var("u"), vocab.getConstant(RDF.TYPE), vocab.getConstant(RDFS.RESOURCE)), //
                    new SPOPredicate[] { //
                        new SPOPredicate(relationName,var("u"), var("a"), var("x"))//
                    },//
                    null // constraints
                    );

        }
 
Example #25
Source File: ForwardChainingRDFSInferencerConnection.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private int applyRuleRdfs7_1()
	throws SailException
{
	int nofInferred = 0;

	Iterator<Statement> ntIter = this.newThisIteration.match(null, null, null);

	while (ntIter.hasNext()) {
		Statement nt = ntIter.next();

		Resource xxx = nt.getSubject();
		URI aaa = nt.getPredicate();
		Value yyy = nt.getObject();

		CloseableIteration<? extends Statement, SailException> t1Iter;
		t1Iter = getWrappedConnection().getStatements(aaa, RDFS.SUBPROPERTYOF, null, true);

		while (t1Iter.hasNext()) {
			Statement t1 = t1Iter.next();

			Value bbb = t1.getObject();
			if (bbb instanceof URI) {
				boolean added = addInferredStatement(xxx, (URI)bbb, yyy);
				if (added) {
					nofInferred++;
				}
			}
		}
		t1Iter.close();
	}

	return nofInferred;
}
 
Example #26
Source File: TestURIExtensionIV.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public void test_InlineURIIV() {

//        doTest(new URIImpl("http://www.bigdata.com"));
        doTest(new URIImpl("http://www.bigdata.com/"));
        doTest(new URIImpl("http://www.bigdata.com/foo"));
        doTest(RDFS.CLASS);
        doTest(RDFS.SUBPROPERTYOF);
        doTest(new URIImpl("http://www.Department0.University0.edu/UndergraduateStudent488"));
        doTest(new URIImpl("http://www.Department0.University0.edu/GraduateStudent15"));
//        doTest(new URIImpl("http://www.bigdata.com:80/foo"));

	}
 
Example #27
Source File: ForwardChainingRDFSInferencerConnection.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private int applyRuleRdfs11_1()
	throws SailException
{
	int nofInferred = 0;

	Iterator<Statement> ntIter = this.newThisIteration.match(null, RDFS.SUBCLASSOF, null);

	while (ntIter.hasNext()) {
		Statement nt = ntIter.next();

		Resource xxx = nt.getSubject();
		Value yyy = nt.getObject();

		if (yyy instanceof Resource) {
			CloseableIteration<? extends Statement, SailException> t1Iter;
			t1Iter = getWrappedConnection().getStatements((Resource)yyy, RDFS.SUBCLASSOF, null, true);

			while (t1Iter.hasNext()) {
				Statement t1 = t1Iter.next();

				Value zzz = t1.getObject();

				if (zzz instanceof Resource) {
					boolean added = addInferredStatement(xxx, RDFS.SUBCLASSOF, zzz);
					if (added) {
						nofInferred++;
					}
				}
			}
			t1Iter.close();
		}
	}

	return nofInferred;
}
 
Example #28
Source File: AbstractTestNanoSparqlClient.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets up a simple data set on the server.
* @throws Exception 
 */
protected void setupQuadsDataOnServer() throws Exception {
    
    final URI mike = new URIImpl(BD.NAMESPACE + "Mike");
    final URI bryan = new URIImpl(BD.NAMESPACE + "Bryan");
    final URI person = new URIImpl(BD.NAMESPACE + "Person");
    final URI likes = new URIImpl(BD.NAMESPACE + "likes");
    final URI rdf = new URIImpl(BD.NAMESPACE + "RDF");
    final URI rdfs = new URIImpl(BD.NAMESPACE + "RDFS");
    final URI c1 = new URIImpl(BD.NAMESPACE + "c1");
    final URI c2 = new URIImpl(BD.NAMESPACE + "c2");
    final URI c3 = new URIImpl(BD.NAMESPACE + "c3");
    final Literal label1 = new LiteralImpl("Mike");
    final Literal label2 = new LiteralImpl("Bryan");

  {
     final Graph g = new LinkedHashModel();
     g.add(mike, RDF.TYPE, person, c1, c2, c3);
     g.add(mike, likes, rdf, c1, c2, c3);
     g.add(mike, RDFS.LABEL, label1, c1, c2, c3);
     g.add(bryan, RDF.TYPE, person, c1, c2, c3);
     g.add(bryan, likes, rdfs, c1, c2, c3);
     g.add(bryan, RDFS.LABEL, label2, c1, c2, c3);
     m_repo.add(new AddOp(g));
  }

}
 
Example #29
Source File: AbstractTestNanoSparqlClient.java    From database with GNU General Public License v2.0 5 votes vote down vote up
protected void doConstructTest(final String method, final RDFFormat format)
            throws Exception {
        
        setupDataOnServer();
        final URI mike = new URIImpl(BD.NAMESPACE + "Mike");
        final URI bryan = new URIImpl(BD.NAMESPACE + "Bryan");
        final URI person = new URIImpl(BD.NAMESPACE + "Person");

        // The expected results.
        final Graph expected = new LinkedHashModel();
        {
//            expected.add(new StatementImpl(mike, likes, rdf));
            expected.add(new StatementImpl(mike, RDF.TYPE, person));
            expected.add(new StatementImpl(bryan, RDF.TYPE, person));
//            expected.add(new StatementImpl(mike, RDFS.LABEL, label1));
        }
        
        // Run the query and verify the results.
        {

            final String queryStr =
                "prefix bd: <"+BD.NAMESPACE+"> " +//
                "prefix rdf: <"+RDF.NAMESPACE+"> " +//
                "prefix rdfs: <"+RDFS.NAMESPACE+"> " +//
                "CONSTRUCT { ?x rdf:type bd:Person }" +//
                "WHERE { " +//
                "  ?x rdf:type bd:Person . " +//
//                "  ?x bd:likes bd:RDF " +//
                "}";

            final IPreparedGraphQuery query = m_repo.prepareGraphQuery(queryStr);

//            final Graph actual = asGraph(query.evaluate());

            assertSameGraph(expected, query);
            
        }
    
    }
 
Example #30
Source File: RDFStoreTest.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testClearNamespaces()
	throws Exception
{
	con.begin();
	con.setNamespace("rdf", RDF.NAMESPACE);
	con.setNamespace("rdfs", RDFS.NAMESPACE);
	con.clearNamespaces();
	con.commit();
	assertTrue(!con.getNamespaces().hasNext());
}