本文整理匯總了Java中com.hp.hpl.jena.rdf.model.StmtIterator類的典型用法代碼示例。如果您正苦於以下問題:Java StmtIterator類的具體用法?Java StmtIterator怎麽用?Java StmtIterator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
StmtIterator類屬於com.hp.hpl.jena.rdf.model包,在下文中一共展示了StmtIterator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parseConfiguration
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入依賴的package包/類
private void parseConfiguration() {
Iterator<Individual> it = this.model.listIndividuals(D2RQ.Configuration);
if (it.hasNext()) {
Resource configResource = it.next();
Configuration configuration = new Configuration(configResource);
StmtIterator stmts = configResource.listProperties(D2RQ.serveVocabulary);
while (stmts.hasNext()) {
configuration.setServeVocabulary(stmts.nextStatement().getBoolean());
}
stmts = configResource.listProperties(D2RQ.useAllOptimizations);
while (stmts.hasNext()) {
configuration.setUseAllOptimizations(stmts.nextStatement().getBoolean());
}
this.mapping.setConfiguration(configuration);
if (it.hasNext())
throw new D2RQException("Only one configuration block is allowed");
}
}
示例2: initializeCategories
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入依賴的package包/類
public Set<String> initializeCategories() {
Model model = ModelFactory.createDefaultModel();
model.read("/home/zwicklbauer/HDTGeneration/skos_categories_en.nt");
StmtIterator it = model.listStatements();
Set<String> set = new HashSet<String>();
System.out.println("Los gehts");
while (it.hasNext()) {
Statement s = it.next();
Resource r = s.getSubject();
Property p = s.getPredicate();
RDFNode n = s.getObject();
if (p.getURI().equalsIgnoreCase(
"http://www.w3.org/2004/02/skos/core#broader")
&& n.isResource()) {
Resource target = n.asResource();
if(!hasSubCategory(target.getURI()))
set.add(target.getURI());
if(!hasSubCategory(r.getURI()))
set.add(r.getURI());
}
}
return set;
}
示例3: main
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入依賴的package包/類
public static void main(String[] args) {
// Set up the ModelD2RQ using a mapping file
ModelD2RQ m = new ModelD2RQ("file:doc/example/mapping-iswc.ttl");
// Find anything with an rdf:type of iswc:InProceedings
StmtIterator paperIt = m.listStatements(null, RDF.type, ISWC.InProceedings);
// List found papers and print their titles
while (paperIt.hasNext()) {
Resource paper = paperIt.nextStatement().getSubject();
System.out.println("Paper: " + paper.getProperty(DC.title).getString());
// List authors of the paper and print their names
StmtIterator authorIt = paper.listProperties(DC.creator);
while (authorIt.hasNext()) {
Resource author = authorIt.nextStatement().getResource();
System.out.println("Author: " + author.getProperty(FOAF.name).getString());
}
System.out.println();
}
m.close();
}
示例4: getUndefinedResources
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入依賴的package包/類
public Collection<Resource> getUndefinedResources(Model model) {
Set<Resource> result = new HashSet<Resource>();
StmtIterator it = model.listStatements();
while (it.hasNext()) {
Statement stmt = it.nextStatement();
if (stmt.getSubject().isURIResource()
&& stmt.getSubject().getURI().startsWith(namespace)
&& !resources.contains(stmt.getSubject())) {
result.add(stmt.getSubject());
}
if (stmt.getPredicate().equals(RDF.type)) continue;
if (stmt.getObject().isURIResource()
&& stmt.getResource().getURI().startsWith(namespace)
&& !resources.contains(stmt.getResource())) {
result.add(stmt.getResource());
}
}
return result;
}
示例5: parseDownloadMap
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入依賴的package包/類
private void parseDownloadMap(DownloadMap dm, Resource r) {
StmtIterator stmts;
stmts = r.listProperties(D2RQ.dataStorage);
while (stmts.hasNext()) {
dm.setDatabase(mapping.database(
stmts.nextStatement().getResource()));
}
stmts = r.listProperties(D2RQ.belongsToClassMap);
while (stmts.hasNext()) {
dm.setBelongsToClassMap(mapping.classMap(
stmts.nextStatement().getResource()));
}
stmts = r.listProperties(D2RQ.contentDownloadColumn);
while (stmts.hasNext()) {
dm.setContentDownloadColumn(stmts.nextStatement().getString());
}
stmts = r.listProperties(D2RQ.mediaType);
while (stmts.hasNext()) {
dm.setMediaType(stmts.nextStatement().getString());
}
}
示例6: getRDFNodes
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入依賴的package包/類
public List<RDFNode> getRDFNodes(Resource r, Property p, NodeType acceptableNodes) {
List<RDFNode> result = new ArrayList<RDFNode>();
StmtIterator it = r.listProperties(p);
while (it.hasNext()) {
Statement stmt = it.next();
remainingTriples.remove(stmt);
if (acceptableNodes.isTypeOf(stmt.getObject())) {
result.add(stmt.getObject());
} else {
if (acceptableNodes.coerce(stmt.getObject()) != null) {
result.add(acceptableNodes.coerce(stmt.getObject()));
}
report.report(acceptableNodes.ifNot, r, p, stmt.getObject());
}
}
Collections.sort(result, RDFComparator.getRDFNodeComparator());
return result;
}
示例7: runQueryOnInstance
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入依賴的package包/類
/**
* 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;
}
示例8: getNumberOfLinks
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入依賴的package包/類
private Integer getNumberOfLinks(String nif) {
Model model = ModelFactory.createDefaultModel();
model.read(new ByteArrayInputStream(nif.getBytes()), null, "TTL");
StmtIterator iter = model.listStatements();
Integer result = 0;
while (iter.hasNext()) {
Statement stm = iter.nextStatement();
if (NIF21Format.RDF_PROPERTY_IDENTREF.equals(stm.getPredicate().toString())) {
result += 1;
}
}
return result;
}
示例9: getAllEntityEvents
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入依賴的package包/類
static ArrayList<String> getAllEntityEvents (Dataset dataset, String entity) {
ArrayList<String> events = new ArrayList<String>();
Iterator<String> it = dataset.listNames();
while (it.hasNext()) {
String name = it.next();
if (!name.equals(instanceGraph) && (!name.equals(provenanceGraph))) {
Model namedModel = dataset.getNamedModel(name);
StmtIterator siter = namedModel.listStatements();
while (siter.hasNext()) {
Statement s = siter.nextStatement();
String object = getObjectValue(s).toLowerCase();
if (object.indexOf(entity.toLowerCase()) > -1) {
String subject = s.getSubject().getURI();
if (!events.contains(subject)) {
events.add(subject);
}
}
}
}
}
return events;
}
示例10: getAllNoteDescriptors
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入依賴的package包/類
public ResourceDescriptor[] getAllNoteDescriptors(String outlineUri) {
Model outlineModel;
try {
outlineModel = MindRaider.outlineCustodian.getModel(outlineUri);
Property property = RDF.type;
String literal = MindRaiderConstants.MR_OWL_CLASS_CONCEPT;
StmtIterator i = outlineModel.listStatements((com.hp.hpl.jena.rdf.model.Resource)null,property,outlineModel.getResource(literal));
ArrayList<String> noteUris=new ArrayList<String>();
while(i.hasNext()) {
Statement s=i.nextStatement();
noteUris.add(s.getSubject().getURI());
}
return getDescriptorsForNoteUris(true, outlineModel, noteUris.toArray(new String[noteUris.size()]));
} catch (Exception e) {
logger.debug("Unable to get resource descriptors",e); // {{debug}}
}
return null;
}
示例11: getFolderUris
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入依賴的package包/類
/**
* Get URIs of all folders.
*
* @return the uri String array
*/
public String[] getFolderUris() {
// TODO cope with discarded folders
ArrayList<String> result = new ArrayList<String>();
StmtIterator i = labelsModel.getModel().listStatements(null, RDF.type,
labelsModel.getResource(MindRaiderConstants.MR_OWL_CLASS_FOLDER));
while (i.hasNext()) {
String folderUri = i.nextStatement().getSubject().getURI();
if (!LABEL_TRASH_URI.equals(folderUri)) {
result.add(folderUri);
}
}
if (result.size() == 0) {
return null;
}
return (String[]) (result.toArray(new String[result.size()]));
}
示例12: createStatement
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入依賴的package包/類
/**
* Create a statement.
*
* @param subject
* the resource
* @param predicateUri
* the predicate url
* @param objectUri
* the object url
* @param literal
* the literal flag
* @return a Statement object
*/
public Statement createStatement(Resource subject, String predicateUri,
String objectUri, boolean literal) {
RDFNode objectResource;
Property predicateResource = model.createProperty(predicateUri);
if (literal) {
objectResource = model.createLiteral(objectUri);
} else {
objectResource = model.createResource(objectUri);
}
subject.addProperty(predicateResource, objectResource);
StmtIterator i = model.listStatements(subject, predicateResource,
objectResource);
if (i.hasNext()) {
return i.nextStatement();
}
JOptionPane.showMessageDialog(MindRaider.mainJFrame,
"Unable to fetch statement.", "Error",
JOptionPane.ERROR_MESSAGE);
return null;
}
示例13: getPropertyValues
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入依賴的package包/類
<T> List<T> getPropertyValues(final Resource resource, final String property, final Function<Statement,Optional<T>> filter) {
Preconditions.checkState(this.model!=null);
final StmtIterator stmts = resource.listProperties(this.model.createProperty(property));
try {
final List<T> values=Lists.newArrayList();
while(stmts.hasNext()) {
final Statement st=stmts.nextStatement();
final Optional<T> result = filter.apply(st);
if(result.isPresent()) {
values.add(result.get());
}
}
return values;
} finally {
stmts.close();
}
}
示例14: execute
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入依賴的package包/類
@Override
public Void execute() throws RuntimeException {
final StmtIterator iterator=
this.model.
listStatements(
null,
this.model.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
this.model.createProperty(this.propertyName));
try {
while(iterator.hasNext()) {
handler(iterator.next());
}
return null;
} finally {
iterator.close();
}
}
示例15: isDisambiguationResource
import com.hp.hpl.jena.rdf.model.StmtIterator; //導入依賴的package包/類
public boolean isDisambiguationResource(String uri) {
if(!linksLoaded){
System.out.println(Settings.EN_DBPEDIA_DISAMBIGUATION_DATASET);
System.out.println(Settings.DE_DBPEDIA_DISAMBIGUATION_DATASET);
System.out.println(Settings.NL_DBPEDIA_DISAMBIGUATION_DATASET);
InputStream in1 = FileManager.get().open( Settings.EN_DBPEDIA_DISAMBIGUATION_DATASET );
InputStream in2 = FileManager.get().open( Settings.DE_DBPEDIA_DISAMBIGUATION_DATASET );
InputStream in3 = FileManager.get().open( Settings.NL_DBPEDIA_DISAMBIGUATION_DATASET );
model.read(in1, null, "N-TRIPLES");
System.out.println("Loaded English disambiguation dataset.");
model.read(in2, null, "N-TRIPLES");
System.out.println("Loaded German disambiguation dataset.");
model.read(in3, null, "N-TRIPLES");
System.out.println("Loaded Dutch disambiguation dataset.");
linksLoaded = true;
}
StmtIterator iter = model.listStatements( new SimpleSelector(
ResourceFactory.createResource(uri),
ResourceFactory.createProperty("http://dbpedia.org/ontology/wikiPageDisambiguates"),
(RDFNode)null));
return iter.hasNext();
}