本文整理匯總了Java中com.hp.hpl.jena.ontology.OntModel.listStatements方法的典型用法代碼示例。如果您正苦於以下問題:Java OntModel.listStatements方法的具體用法?Java OntModel.listStatements怎麽用?Java OntModel.listStatements使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hp.hpl.jena.ontology.OntModel
的用法示例。
在下文中一共展示了OntModel.listStatements方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
@Test
public void test() {
// create an empty ontology model using Pellet spec
final OntModel model = ModelFactory
.createOntologyModel(InferrayReasonerFactory.INFERRAY_RDFSPLUS);
// final OntModel model = ModelFactory
// .createOntologyModel(OntModelSpec.RDFS_MEM_TRANS_INF);
// read the file
try {
final long t1 = System.currentTimeMillis();
final InputStream is = new FileInputStream(input);
// model.read(is, null);// , "N-TRIPLES"
// List the countries
final StmtIterator it = model.listStatements();
final Set<com.hp.hpl.jena.rdf.model.Statement> set = it.toSet();
System.out.println((System.currentTimeMillis() - t1) + "ms");
System.out.println(set.size());
} catch (final FileNotFoundException e) {
e.printStackTrace();
return;
}
}
示例2: checkRangeForMatch
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
private boolean checkRangeForMatch(OntModel theJenaModel2, OntProperty pred, OntResource obj, boolean isList) throws CircularDependencyException {
StmtIterator rngitr = theJenaModel2.listStatements(pred, RDFS.range, (RDFNode)null);
while (rngitr.hasNext()) {
RDFNode rng = rngitr.nextStatement().getObject();
if (isTypedListSubclass(rng)) {
if (!isList) {
rngitr.close();
return false;
}
if (rng.canAs(OntClass.class )) {
rng = getSadlTypedListType(rng.as(OntClass.class));
}
else {
// TODO this is an unhandled case
}
}
if (obj instanceof Individual) {
ExtendedIterator<Resource> institr = obj.asIndividual().listRDFTypes(true);
while (institr.hasNext()) {
Resource typ = institr.next();
if (rng.canAs(OntClass.class)) {
if (SadlUtils.classIsSubclassOf(typ.as(OntClass.class), rng.asResource().as(OntClass.class), true, null)) {
institr.close();
rngitr.close();
return true;
}
}
}
}
else if (obj.canAs(OntClass.class) && rng.isResource() && rng.asResource().canAs(OntClass.class)) {
if (SadlUtils.classIsSubclassOf(obj.as(OntClass.class), rng.asResource().as(OntClass.class), true, null)) {
rngitr.close();
return true;
}
}
}
return false;
}
示例3: updateCityInformation
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
/**
* This method detects if the loaded knowledge has some city information and calls to external
* Ontologies to link their data with the loaded knowledge.
*
* @param pFinalResult: The loaded and inferred knowledge.
*/
private void updateCityInformation(OntModel pFinalResult) {
// Defining the list of target cities to obtain desired information
final List<String> places = Arrays.asList("lecce", "singapore", "madrid", "birmingham", "montpellier", "athens",
"LECCE", "SINGAPORE", "MADRID", "BIRMINGHAM", "MONTPELLIER", "ATHENS");
// Iterate loaded statements of the model.
StmtIterator iter = pFinalResult.listStatements();
try {
while (iter.hasNext()) {
Statement stmt = iter.next();
// Obtain the data from resources
Resource s = stmt.getSubject();
Property p = stmt.getPredicate();
RDFNode o = stmt.getObject();
// Prepare some values for evaluations
String sURI = new String();
String pURI = new String();
String oURI = new String();
// Assing the values of the current statement
if (s.isURIResource()) {
// We get the URI
sURI = s.getURI();
} else if (s.isAnon()) {
System.out.print("blank");
}
if (p.isURIResource())
// We get the URI.
pURI = p.getURI();
if (o.isURIResource()) {
// We get the URI
oURI = o.asResource().getURI();
} else if (o.isAnon()) {
System.out.print("blank");
} else if (o.isLiteral()) {
oURI = o.asLiteral().getString(); // Getting the literal value (city name)
}
// baseuri:pilot:pilot_name/23232 hasPilotname "lecce";
// SUJETO
// baseURI + /city4age_ar/pilot/*
// base URI /city4age_sr/pilot/*
// Predicado
// dbp:name
// Objeto
// Literal que sea una lista de ciudades
if (sURI.equals(c4aBaseURI+"Pilot") && pURI.equals("dbp:name") && oURI.toLowerCase().equals(places)) {
LOGGER.info("--> updateCityInformation: Searching information from city: "+oURI.toLowerCase());
// Obtaining aditional resources of external ontologies
this.obtainCityInformation(oURI.toLowerCase(), pFinalResult);
}
}
}catch (Exception e) {
// We are goingi to raise the default exception. It can be raised from the method obtainCityInformation
LOGGER.severe("--> updateCityInformation: An error happened when trying to update city information: ");
System.err.println("--> updateCityInformation: An error happened when trying to update city information: ");
e.printStackTrace();
} finally {
if (iter != null) iter.close();
}
}