Java Code Examples for com.hp.hpl.jena.rdf.model.StmtIterator#nextStatement()
The following examples show how to use
com.hp.hpl.jena.rdf.model.StmtIterator#nextStatement() .
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: 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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
Source File: SelectEntityTrig.java From EventCoreference with Apache License 2.0 | 4 votes |
static public void main (String[] args) { String trigfolderPath = ""; trigfolderPath = "/Users/piek/Desktop/tweede-kamer/events"; String entity = ""; String date = ""; entity = "lippens"; for (int i = 0; i < args.length; i++) { String arg = args[i]; if (arg.equals("--trig-folder") && args.length>(i+1)) { trigfolderPath = args[i+1]; } else if (arg.equals("--entity") && args.length>(i+1)) { entity = args[i+1]; } else if (arg.equals("--event-date") && args.length>(i+1)) { date = args[i+1]; } } if (entity.isEmpty()) { System.out.println("Entity is empty"); return; } File trigfolder = new File(trigfolderPath); String trigEntityPath = trigfolder.getParent()+"/"+entity; File entityTrigFolder = new File (trigEntityPath); if (!entityTrigFolder.exists()) { entityTrigFolder.mkdir(); } if (!entityTrigFolder.exists()) { System.out.println("Could not create entity trig folder"); return; } dataset = TDBFactory.createDataset(); ArrayList<File> trigFiles = Util.makeRecursiveFileList(trigfolder, ".trig"); System.out.println(trigfolder.getName() + " trigFiles.size() = " + trigFiles.size()); int cnt = 1; for (int i = 0; i < trigFiles.size(); i++) { File file = trigFiles.get(i); if (!file.getParentFile().getName().startsWith(date)) { continue; } if (i%500==0) { System.out.println("i = " + i); // if (i>1000) break; } ArrayList<String> events = new ArrayList<String>(); dataset = RDFDataMgr.loadDataset(file.getAbsolutePath()); Model namedModel = dataset.getNamedModel(TrigUtil.instanceGraph); StmtIterator siter = namedModel.listStatements(); while (siter.hasNext()) { Statement s = siter.nextStatement(); String subject = s.getSubject().getURI().toLowerCase(); if (subject.indexOf(entity.toLowerCase())>-1) { String trigName = trigEntityPath+"/"+cnt+"_"+file.getName(); File trigCopy = new File(trigName); copyFile(file, trigCopy); cnt++; break; } } dataset = null; } }