當前位置: 首頁>>代碼示例>>Java>>正文


Java RDF.NAMESPACE屬性代碼示例

本文整理匯總了Java中org.openrdf.model.vocabulary.RDF.NAMESPACE屬性的典型用法代碼示例。如果您正苦於以下問題:Java RDF.NAMESPACE屬性的具體用法?Java RDF.NAMESPACE怎麽用?Java RDF.NAMESPACE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.openrdf.model.vocabulary.RDF的用法示例。


在下文中一共展示了RDF.NAMESPACE屬性的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: endElement

@Override
public void endElement(String uri, String localName, String qName)
		throws SAXException {
	super.endElement(uri, localName, qName);
	stack.pop();
	if (stack.size() == 0) {
		super.endElement(RDF.NAMESPACE, "RDF", "rdf:RDF");
		try {
			String data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
			data += writer.toString();
			writer.reset();
			outputStream.writeObject(data);
		} catch (IOException e) {
			throw new SAXException(e);
		} finally {
		}
	}
}
 
開發者ID:erfgoed-en-locatie,項目名稱:artsholland-platform,代碼行數:18,代碼來源:StreamingToRDFContentHandler.java

示例2: applyRuleX1

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;
}
 
開發者ID:semweb4j,項目名稱:semweb4j,代碼行數:24,代碼來源:ForwardChainingRDFSInferencerConnection.java

示例3: testEquivPropOf

public void testEquivPropOf() throws Exception {
      if(internalInferenceEngine == null)
 {
	return; //infer not supported;
}

      RepositoryConnection conn = repository.getConnection();
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "undergradDegreeFrom"), OWL.EQUIVALENTPROPERTY, vf.createURI(litdupsNS, "ugradDegreeFrom")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "UgradA"), vf.createURI(litdupsNS, "undergradDegreeFrom"), vf.createURI(litdupsNS, "Harvard")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "GradB"), vf.createURI(litdupsNS, "ugradDegreeFrom"), vf.createURI(litdupsNS, "Harvard")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "GradC"), vf.createURI(litdupsNS, "ugraduateDegreeFrom"), vf.createURI(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();
  }
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:30,代碼來源:RdfCloudTripleStoreConnectionTest.java

示例4: testInverseOf

public void testInverseOf() throws Exception {
      if(internalInferenceEngine == null)
 {
	return; //infer not supported;
}

      RepositoryConnection conn = repository.getConnection();
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "degreeFrom"), OWL.INVERSEOF, vf.createURI(litdupsNS, "hasAlumnus")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "UgradA"), vf.createURI(litdupsNS, "degreeFrom"), vf.createURI(litdupsNS, "Harvard")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "GradB"), vf.createURI(litdupsNS, "degreeFrom"), vf.createURI(litdupsNS, "Harvard")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "Harvard"), vf.createURI(litdupsNS, "hasAlumnus"), vf.createURI(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();
  }
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:40,代碼來源:RdfCloudTripleStoreConnectionTest.java

示例5: getMemberPredicate

private URI getMemberPredicate(int index) {
	ObjectConnection conn = getObjectConnection();
	Repository repository;
	repository = conn.getRepository();
	String uri = RDF.NAMESPACE + '_' + (index + 1);
	return repository.getValueFactory().createURI(uri);
}
 
開發者ID:anno4j,項目名稱:anno4j,代碼行數:7,代碼來源:RDFSContainer.java

示例6: startElement

@Override
public void startElement(String uri, String localName, String qName,
		Attributes atts) throws SAXException {
	if (stack.size() == 0) {
		for (Entry<String, String> ns : namespaces.entrySet()) {
			super.startPrefixMapping(ns.getKey(), ns.getValue());
		}
		super.startPrefixMapping("rdf", RDF.NAMESPACE);
		super.startPrefixMapping("xml","http://www.w3.org/XML/1998/namespace");
		super.startElement(RDF.NAMESPACE, "RDF", "rdf:RDF", new AttributesImpl());
	}
	super.startElement(uri, localName, qName, atts);
	stack.push(qName);
}
 
開發者ID:erfgoed-en-locatie,項目名稱:artsholland-platform,代碼行數:14,代碼來源:StreamingToRDFContentHandler.java

示例7: loadProperties

private void loadProperties() {
	properties = new HashMap<URI, Property>();

	String sparql = "prefix ssn: <" + SSN.ns + "#>" + "prefix rdf: <"
			+ RDF.NAMESPACE + ">" + "select ?id " + "where {"
			+ "?id rdf:type ssn:Property ." + "}";

	try {
		TupleQuery query = connection.prepareTupleQuery(
				QueryLanguage.SPARQL, sparql);
		TupleQueryResult rs = query.evaluate();

		while (rs.hasNext()) {
			BindingSet bs = rs.next();

			URI id = _uri(bs.getValue("id"));
			Property property = new Property(id);

			properties.put(id, property);
		}

	} catch (RepositoryException | MalformedQueryException
			| QueryEvaluationException e) {
		if (log.isLoggable(Level.SEVERE))
			log.severe(e.getMessage());
	}

	if (log.isLoggable(Level.INFO))
		log.info("Loaded properties (" + properties.size() + ") {"
				+ properties + "}");
}
 
開發者ID:markusstocker,項目名稱:emrooz,代碼行數:31,代碼來源:SesameKnowledgeStore.java

示例8: loadFeatures

private void loadFeatures() {
	features = new HashMap<URI, FeatureOfInterest>();

	String sparql = "prefix ssn: <" + SSN.ns + "#>" + "prefix rdf: <"
			+ RDF.NAMESPACE + ">" + "select ?id " + "where {"
			+ "?id rdf:type ssn:FeatureOfInterest ." + "}";

	try {
		TupleQuery query = connection.prepareTupleQuery(
				QueryLanguage.SPARQL, sparql);
		TupleQueryResult rs = query.evaluate();

		while (rs.hasNext()) {
			BindingSet bs = rs.next();

			URI id = _uri(bs.getValue("id"));
			FeatureOfInterest feature = new FeatureOfInterest(id);

			features.put(id, feature);
		}

	} catch (RepositoryException | MalformedQueryException
			| QueryEvaluationException e) {
		if (log.isLoggable(Level.SEVERE))
			log.severe(e.getMessage());
	}

	if (log.isLoggable(Level.INFO))
		log.info("Loaded features of interest (" + features.size() + ") {"
				+ features + "}");
}
 
開發者ID:markusstocker,項目名稱:emrooz,代碼行數:31,代碼來源:SesameKnowledgeStore.java

示例9: testSubPropertyOf

public void testSubPropertyOf() throws Exception {
      if(internalInferenceEngine == null)
 {
	return; //infer not supported;
}

      RepositoryConnection conn = repository.getConnection();
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "undergradDegreeFrom"), RDFS.SUBPROPERTYOF, vf.createURI(litdupsNS, "degreeFrom")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "gradDegreeFrom"), RDFS.SUBPROPERTYOF, vf.createURI(litdupsNS, "degreeFrom")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "degreeFrom"), RDFS.SUBPROPERTYOF, vf.createURI(litdupsNS, "memberOf")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "memberOf"), RDFS.SUBPROPERTYOF, vf.createURI(litdupsNS, "associatedWith")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "UgradA"), vf.createURI(litdupsNS, "undergradDegreeFrom"), vf.createURI(litdupsNS, "Harvard")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "GradB"), vf.createURI(litdupsNS, "gradDegreeFrom"), vf.createURI(litdupsNS, "Yale")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "ProfessorC"), vf.createURI(litdupsNS, "memberOf"), vf.createURI(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();
  }
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:63,代碼來源:RdfCloudTripleStoreConnectionTest.java

示例10: testSymmPropOf

public void testSymmPropOf() throws Exception {
      if(internalInferenceEngine == null)
 {
	return; //infer not supported;
}

      RepositoryConnection conn = repository.getConnection();
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "friendOf"), RDF.TYPE, OWL.SYMMETRICPROPERTY));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "Bob"), vf.createURI(litdupsNS, "friendOf"), vf.createURI(litdupsNS, "Jeff")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "James"), vf.createURI(litdupsNS, "friendOf"), vf.createURI(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();
  }
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:49,代碼來源:RdfCloudTripleStoreConnectionTest.java

示例11: testTransitiveProp

public void testTransitiveProp() throws Exception {
      if(internalInferenceEngine == null)
 {
	return; //infer not supported;
}

      RepositoryConnection conn = repository.getConnection();
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "subRegionOf"), RDF.TYPE, OWL.TRANSITIVEPROPERTY));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "Queens"), vf.createURI(litdupsNS, "subRegionOf"), vf.createURI(litdupsNS, "NYC")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "NYC"), vf.createURI(litdupsNS, "subRegionOf"), vf.createURI(litdupsNS, "NY")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "NY"), vf.createURI(litdupsNS, "subRegionOf"), vf.createURI(litdupsNS, "US")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "US"), vf.createURI(litdupsNS, "subRegionOf"), vf.createURI(litdupsNS, "NorthAmerica")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "NorthAmerica"), vf.createURI(litdupsNS, "subRegionOf"), vf.createURI(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();
  }
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:62,代碼來源:RdfCloudTripleStoreConnectionTest.java

示例12: testSubClassOf

public void testSubClassOf() throws Exception {
      if(internalInferenceEngine == null)
 {
	return; //infer not supported;
}

      RepositoryConnection conn = repository.getConnection();
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "UndergraduateStudent"), RDFS.SUBCLASSOF, vf.createURI(litdupsNS, "Student")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "Student"), RDFS.SUBCLASSOF, vf.createURI(litdupsNS, "Person")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "UgradA"), RDF.TYPE, vf.createURI(litdupsNS, "UndergraduateStudent")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "StudentB"), RDF.TYPE, vf.createURI(litdupsNS, "Student")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "PersonC"), RDF.TYPE, vf.createURI(litdupsNS, "Person")));
      conn.commit();
      conn.close();

      internalInferenceEngine.refreshGraph();

      conn = repository.getConnection();

      //simple api first
      RepositoryResult<Statement> person = conn.getStatements(null, RDF.TYPE, vf.createURI(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();
  }
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:61,代碼來源:RdfCloudTripleStoreConnectionTest.java

示例13: testSameAs

public void testSameAs() throws Exception {
      if(internalInferenceEngine == null)
 {
	return; //infer not supported;
}

      RepositoryConnection conn = repository.getConnection();
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "StudentA1"), OWL.SAMEAS, vf.createURI(litdupsNS, "StudentA2")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "StudentA2"), OWL.SAMEAS, vf.createURI(litdupsNS, "StudentA3")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "StudentB1"), OWL.SAMEAS, vf.createURI(litdupsNS, "StudentB2")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "StudentB2"), OWL.SAMEAS, vf.createURI(litdupsNS, "StudentB3")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "StudentA1"), vf.createURI(litdupsNS, "pred1"), vf.createURI(litdupsNS, "StudentB3")));
      conn.add(new StatementImpl(vf.createURI(litdupsNS, "StudentB1"), vf.createURI(litdupsNS, "pred2"), vf.createURI(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();
  }
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:77,代碼來源:RdfCloudTripleStoreConnectionTest.java


注:本文中的org.openrdf.model.vocabulary.RDF.NAMESPACE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。