com.hp.hpl.jena.rdf.model.StmtIterator Java Examples
The following examples show how to use
com.hp.hpl.jena.rdf.model.StmtIterator.
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: WP2N3JenaWriterPP.java From GeoTriples with Apache License 2.0 | 6 votes |
@Override protected int countProperties(Resource r, Property p) { int numProp = 0 ; StmtIterator sIter = r.listProperties(p) ; for ( ; sIter.hasNext() ; ) { Statement stmnt=sIter.nextStatement() ; if(! stmnt.getObject().toString().startsWith("null")) { numProp++ ; } } sIter.close() ; return numProp ; }
Example #2
Source File: R2RMLReader.java From GeoTriples with Apache License 2.0 | 6 votes |
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; }
Example #3
Source File: D2RQReader.java From GeoTriples with Apache License 2.0 | 6 votes |
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()); } }
Example #4
Source File: SparqlExtractor.java From wandora with GNU General Public License v3.0 | 6 votes |
public void RDF2TopicMap(Model model, TopicMap map) { // list the statements in the Model StmtIterator iter = model.listStatements(); Statement stmt = null; int counter = 0; while (iter.hasNext() && !forceStop()) { try { stmt = iter.nextStatement(); // get next statement handleStatement(stmt, map); } catch(Exception e) { log(e); } counter++; setProgress(counter); if(counter % 100 == 0) hlog("RDF statements processed: " + counter); } log("Total RDF statements processed: " + counter); }
Example #5
Source File: D2RQReader.java From GeoTriples with Apache License 2.0 | 6 votes |
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"); } }
Example #6
Source File: VocabularySummarizer.java From GeoTriples with Apache License 2.0 | 6 votes |
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; }
Example #7
Source File: TrigUtil.java From EventCoreference with Apache License 2.0 | 6 votes |
static public 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; }
Example #8
Source File: JenaModelExample.java From GeoTriples with Apache License 2.0 | 6 votes |
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(); }
Example #9
Source File: GeneralR2RMLCompiler.java From GeoTriples with Apache License 2.0 | 6 votes |
public List<RDFNode> getRDFNodes(Resource r, Property p, R2RMLReader.NodeType acceptableNodes) { List<RDFNode> result = new ArrayList<RDFNode>(); StmtIterator it = r.listProperties(p); while (it.hasNext()) { Statement stmt = it.next(); if (acceptableNodes.isTypeOf(stmt.getObject())) { result.add(stmt.getObject()); } else { if (acceptableNodes.coerce(stmt.getObject()) != null) { result.add(acceptableNodes.coerce(stmt.getObject())); } } } Collections.sort(result, RDFComparator.getRDFNodeComparator()); return result; }
Example #10
Source File: WriteStatementsKnowledgeStore.java From EventCoreference with Apache License 2.0 | 5 votes |
static public void main (String[] args) { Dataset dataset = null; String address = "http://145.100.57.176:50053/"; ArrayList<org.openrdf.model.Statement> statements = new ArrayList<org.openrdf.model.Statement>(); Iterator<String> it = dataset.listNames(); while (it.hasNext()) { String name = it.next(); Model namedModel = dataset.getNamedModel(name); StmtIterator siter = namedModel.listStatements(); while (siter.hasNext()) { com.hp.hpl.jena.rdf.model.Statement s = siter.nextStatement(); org.openrdf.model.Statement statement =castJenaOpenRdf(s, name); if (statement!=null) { statements.add(statement); } } } if (DEBUG) { try { ByteArrayOutputStream os = new ByteArrayOutputStream(); RDFDataMgr.write(os, dataset, RDFFormat.TRIG_PRETTY); String rdfString = new String(os.toByteArray(), "UTF-8"); System.out.println("rdfString = " + rdfString); os.close(); } catch (Exception e) { e.printStackTrace(); } } // System.out.println("address = " + address); WriteStatementsKnowledgeStore.storeTriples(statements, address); }
Example #11
Source File: RdfGeneratorTest.java From xcurator with Apache License 2.0 | 5 votes |
/** * Run the RDF generator pipeline for clinical trial data Before running * this, run the Mapping Discovery Test first to generate the mapping file * for clinical trials. * * @throws SAXException * @throws IOException * @throws ParserConfigurationException */ @Test public void test_generateRdfs_clinical_trials() throws SAXException, IOException, ParserConfigurationException { // Setup deserializer mappingDeserialization = new XmlBasedMappingDeserialization( new FileInputStream("output/clinicaltrials-mapping.xml"), parser); Document dataDocument = parser.parse(RdfGeneratorTest.class.getResourceAsStream( "/clinicaltrials/data/content.xml"), 10); rdfGenerator = new RdfGenerator(new DataDocument(dataDocument), new XmlBasedMapping()); // Add steps rdfGenerator.addStep(mappingDeserialization); rdfGenerator.addStep(rdfGeneration); // Generate rdfGenerator.generateRdfs(); // Verify Model model = TDBFactory.createModel(testTdbDir); Assert.assertFalse("No RDF was generated. TDB directory: " + testTdbDir, model.isEmpty()); ResIterator iter = model.listResourcesWithProperty(RDF.type); while (iter.hasNext()) { Resource resource = iter.nextResource(); System.out.println(resource.getLocalName()); StmtIterator iterStm = resource.listProperties(); while (iterStm.hasNext()) { System.out.println(iterStm.nextStatement().toString()); } } }
Example #12
Source File: RdfGeneratorTest2.java From xcurator with Apache License 2.0 | 5 votes |
/** * Run the RDF generator pipeline for clinical trial data Before running * this, run the Mapping Discovery Test first to generate the mapping file * for clinical trials. * * @throws SAXException * @throws IOException * @throws ParserConfigurationException */ @Test public void test_generateRdfs_clinical_trials() throws SAXException, IOException, ParserConfigurationException { // Setup deserializer mappingDeserialization = new XmlBasedMappingDeserialization( new FileInputStream("output/clinicaltrials-mapping.xml"), parser); Document dataDocument = parser.parse(RdfGeneratorTest2.class.getResourceAsStream( "/clinicaltrials/data/content.xml"), 10); rdfGenerator = new RdfGenerator(new DataDocument(dataDocument), new XmlBasedMapping()); // Add steps rdfGenerator.addStep(mappingDeserialization); rdfGenerator.addStep(rdfGeneration); // Generate rdfGenerator.generateRdfs(); // Verify Model model = TDBFactory.createModel(testTdbDir); Assert.assertFalse("No RDF was generated. TDB directory: " + testTdbDir, model.isEmpty()); ResIterator iter = model.listResourcesWithProperty(RDF.type); while (iter.hasNext()) { Resource resource = iter.nextResource(); System.out.println(resource.getLocalName()); StmtIterator iterStm = resource.listProperties(); while (iterStm.hasNext()) { System.out.println(iterStm.nextStatement().toString()); } } }
Example #13
Source File: JenaUtils.java From xcurator with Apache License 2.0 | 5 votes |
public static List<Statement> getBestMatchingStatements(OntModel ontology, StringMetric metric, String term) { StmtIterator iter = ontology.listStatements(new SimpleSelector(null, RDFS.label, (RDFNode) null)); double maxSimilarity = Double.MIN_VALUE; List<Statement> bestChoices = new LinkedList<Statement>(); while (iter.hasNext()) { Statement st = iter.next(); String objectStr = st.getObject().asLiteral().getString(); double similarity = metric.getSimilarity(term, objectStr); if (similarity <= 0) { continue; } if (similarity > maxSimilarity) { maxSimilarity = similarity; bestChoices.clear(); } else if (similarity == maxSimilarity) { bestChoices.add(st); } } return bestChoices; }
Example #14
Source File: OpenCycOntology.java From xcurator with Apache License 2.0 | 5 votes |
private Set<String> getTypesOfSubject(Resource subject) { Set<String> ret = new HashSet<String>(); StmtIterator stiter2 = model.listStatements(new SimpleSelector(subject, RDF.type, (RDFNode) null)); while (stiter2.hasNext()) { String uri = stiter2.next().getObject().asResource().getURI(); if (uri.startsWith("http://sw.opencyc.org")) { ret.add(uri); } } return ret; }
Example #15
Source File: SolRDF.java From SolRDF with Apache License 2.0 | 5 votes |
/** * Adds a given set of statements to a named graph. * * @param uri the graph URI. * @param iterator the statements iterator. * @throws UnableToAddException in case of add (local or remote) failure. */ public void add(final String uri, final StmtIterator iterator) throws UnableToAddException { try { remoteDataset.add(uri, model(uri).add(iterator)); } catch (final Exception exception) { throw new UnableToAddException(exception); } }
Example #16
Source File: SolRDF.java From SolRDF with Apache License 2.0 | 5 votes |
/** * Adds a given set of statements to the unnamed graph. * * @param iterator the statements iterator. * @throws UnableToAddException in case of add (local or remote) failure. */ public void add(final StmtIterator iterator) throws UnableToAddException { try { remoteDataset.add(model().add(iterator)); } catch (final Exception exception) { throw new UnableToAddException(exception); } }
Example #17
Source File: ScannerFactory.java From DataHubSystem with GNU Affero General Public License v3.0 | 5 votes |
/** * Retrieve the dhus system supported items for file scanning processing. * Is considered supported all classes having * <code>http://www.gael.fr/dhus#metadataExtractor</code> property * connection. * @return the list of supported class names. */ public static synchronized String[] getDefaultCortexSupport () { DrbCortexModel model; try { model = DrbCortexModel.getDefaultModel (); } catch (IOException e) { throw new UnsupportedOperationException ( "Drb cortex not properly initialized."); } ExtendedIterator it=model.getCortexModel ().getOntModel ().listClasses (); List<String>list = new ArrayList<String> (); while (it.hasNext ()) { OntClass cl = (OntClass)it.next (); OntProperty metadata_extractor_p = cl.getOntModel().getOntProperty( "http://www.gael.fr/dhus#support"); StmtIterator properties = cl.listProperties (metadata_extractor_p); while (properties.hasNext ()) { Statement stmt = properties.nextStatement (); LOGGER.debug ("Scanner Support Added for " + stmt.getSubject ().toString ()); list.add (stmt.getSubject ().toString ()); } } return list.toArray (new String[list.size ()]); }
Example #18
Source File: Course.java From neo4jena with Apache License 2.0 | 5 votes |
public static void write(GraphDatabaseService njgraph) { InputStream in = FileManager.get().open( inputFileName ); if (in == null) { throw new IllegalArgumentException( "File: " + inputFileName + " not found"); } Model model = ModelFactory.createDefaultModel(); model.read(in,"","TTL"); double triples = model.size(); log.info("Model loaded with " + triples + " triples"); System.out.println("Model loaded with " + triples + " triples"); Map<String, String> prefixMap = model.getNsPrefixMap(); // System.out.println("Prefix Mapping: " + prefixMap); NeoGraph graph = new NeoGraph(njgraph); graph.getPrefixMapping().setNsPrefixes(prefixMap); graph.startBulkLoad(); log.info("Connection created"); Model njmodel = ModelFactory.createModelForGraph(graph); log.info("NeoGraph Model initiated"); System.out.println("NeoGraph Model initiated"); //log.info(njmodel.add(model)); //njmodel.add(model); StmtIterator iterator = model.listStatements(); StopWatch watch = new StopWatch(); int count = 0; while(iterator.hasNext()){ njmodel.add(iterator.next()); count++; } System.out.println("Total triples loaded are:"+ count); graph.stopBulkLoad(); //log.info("Storing completed (ms): " + watch.stop()); System.out.println("Storing completed (ms): " + watch.stop()); }
Example #19
Source File: GetEventStats.java From EventCoreference with Apache License 2.0 | 5 votes |
static ArrayList<String> getAllEsoEvents (Dataset dataset, ArrayList<String> esoTypes) { ArrayList<String> events = new ArrayList<String>(); Iterator<String> it = dataset.listNames(); while (it.hasNext()) { String name = it.next(); if (name.equals(instanceGraph)) { Model namedModel = dataset.getNamedModel(name); StmtIterator siter = namedModel.listStatements(); while (siter.hasNext()) { Statement s = siter.nextStatement(); // System.out.println("s.toString() = " + s.toString()); if (s.getPredicate().toString().endsWith("#type")) { for (int i = 0; i < esoTypes.size(); i++) { String esoType = esoTypes.get(i); if (s.getObject().toString().endsWith(esoType)) { String subject = s.getSubject().getURI(); if (!events.contains(subject)) { events.add(subject); } break; } } } } } } return events; }
Example #20
Source File: R2RMLReader.java From GeoTriples with Apache License 2.0 | 5 votes |
private void checkForSpuriousTriples() { StmtIterator it = remainingTriples.listStatements(); while (it.hasNext()) { Statement stmt = it.next(); report.report(Problem.SPURIOUS_TRIPLE, stmt.getSubject(), stmt.getPredicate(), stmt.getObject()); } }
Example #21
Source File: D2RQReader.java From GeoTriples with Apache License 2.0 | 5 votes |
private void parsePropertyBridges() { StmtIterator stmts = this.model.listStatements(null, D2RQ.belongsToClassMap, (RDFNode) null); while (stmts.hasNext()) { Statement stmt = stmts.nextStatement(); ClassMap classMap = this.mapping.classMap(stmt.getResource()); Resource r = stmt.getSubject(); PropertyBridge bridge = new PropertyBridge(r); bridge.setBelongsToClassMap(classMap); parseResourceMap(bridge, r); parsePropertyBridge(bridge, r); } }
Example #22
Source File: D2RQReader.java From GeoTriples with Apache License 2.0 | 5 votes |
private void parseTranslationTables() { Set<Resource> translationTableResources = new HashSet<Resource>(); Iterator<? extends Resource> it = this.model.listIndividuals(D2RQ.TranslationTable); while (it.hasNext()) { translationTableResources.add(it.next()); } StmtIterator stmts; stmts = this.model.listStatements(null, D2RQ.translateWith, (Resource) null); while (stmts.hasNext()) { translationTableResources.add(stmts.nextStatement().getResource()); } stmts = this.model.listStatements(null, D2RQ.translation, (RDFNode) null); while (stmts.hasNext()) { translationTableResources.add(stmts.nextStatement().getSubject()); } stmts = this.model.listStatements(null, D2RQ.javaClass, (RDFNode) null); while (stmts.hasNext()) { translationTableResources.add(stmts.nextStatement().getSubject()); } stmts = this.model.listStatements(null, D2RQ.href, (RDFNode) null); while (stmts.hasNext()) { translationTableResources.add(stmts.nextStatement().getSubject()); } it = translationTableResources.iterator(); while (it.hasNext()) { Resource r = it.next(); TranslationTable table = new TranslationTable(r); parseTranslationTable(table, r); this.mapping.addTranslationTable(table); } }
Example #23
Source File: DatasetDescriptionServlet.java From GeoTriples with Apache License 2.0 | 5 votes |
private static Set<Resource> generatePartitions(Model m, Resource type, Property p) { Set<Resource> partitions = new HashSet<Resource>(); ResIterator classIt = m.listResourcesWithProperty(RDF.type, type); while (classIt.hasNext()) { Resource classMap = classIt.next(); StmtIterator pIt = classMap.listProperties(p); while (pIt.hasNext()) { partitions.add((Resource) pIt.next().getObject()); } } return partitions; }
Example #24
Source File: PageServlet.java From GeoTriples with Apache License 2.0 | 5 votes |
private Collection<Property> collectProperties(Model m, Resource r) { Collection<Property> result = new TreeSet<Property>(); StmtIterator it = r.listProperties(); while (it.hasNext()) { result.add(new Property(it.nextStatement(), false)); } it = m.listStatements(null, null, r); while (it.hasNext()) { result.add(new Property(it.nextStatement(), true)); } return result; }
Example #25
Source File: VocabularySummarizer.java From GeoTriples with Apache License 2.0 | 5 votes |
public Model triplesInvolvingVocabulary(Model model) { Model result = ModelFactory.createDefaultModel(); result.getNsPrefixMap().putAll(model.getNsPrefixMap()); StmtIterator it = model.listStatements(); while (it.hasNext()) { Statement stmt = it.next(); if (properties.contains(stmt.getPredicate()) || (stmt.getPredicate().equals(RDF.type) && classes.contains(stmt.getObject()))) { result.add(stmt); } } return result; }
Example #26
Source File: VocabularySummarizer.java From GeoTriples with Apache License 2.0 | 5 votes |
public boolean usesVocabulary(Model model) { StmtIterator it = model.listStatements(); while (it.hasNext()) { Statement stmt = it.nextStatement(); if (stmt.getPredicate().getURI().startsWith(namespace)) { return true; } if (stmt.getPredicate().equals(RDF.type) && stmt.getResource().getURI().startsWith(namespace)) { return true; } } return false; }
Example #27
Source File: VocabularySummarizer.java From GeoTriples with Apache License 2.0 | 5 votes |
public Collection<Property> getUndefinedProperties(Model model) { Set<Property> result = new HashSet<Property>(); StmtIterator it = model.listStatements(); while (it.hasNext()) { Statement stmt = it.nextStatement(); if (stmt.getPredicate().getURI().startsWith(namespace) && !properties.contains(stmt.getPredicate())) { result.add(stmt.getPredicate()); } } return result; }
Example #28
Source File: VocabularySummarizer.java From GeoTriples with Apache License 2.0 | 5 votes |
public Collection<Resource> getUndefinedClasses(Model model) { Set<Resource> result = new HashSet<Resource>(); StmtIterator it = model.listStatements(null, RDF.type, (RDFNode) null); while (it.hasNext()) { Statement stmt = it.nextStatement(); if (stmt.getObject().isURIResource() && stmt.getResource().getURI().startsWith(namespace) && !classes.contains(stmt.getObject())) { result.add(stmt.getResource()); } } return result; }
Example #29
Source File: WP2RDFXMLWriter.java From GeoTriples with Apache License 2.0 | 5 votes |
protected void writeRDFStatements(Model model, Resource subject, PrintWriter writer) { StmtIterator sIter = model .listStatements(subject, null, (RDFNode) null); writeDescriptionHeader(subject, writer); while (sIter.hasNext()) { Statement nextSt = sIter.nextStatement(); if (nextSt.getObject().toString().startsWith("null^^")) { sIter.nextStatement(); continue; } writePredicate(nextSt, writer); } writeDescriptionTrailer(subject, writer); }
Example #30
Source File: BatchHandler.java From neo4jena with Apache License 2.0 | 4 votes |
@Override public void addedStatements(StmtIterator arg0) { // TODO Auto-generated method stub }