Java Code Examples for com.hp.hpl.jena.rdf.model.StmtIterator

The following examples show how to use com.hp.hpl.jena.rdf.model.StmtIterator. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: GeoTriples   Source File: WP2N3JenaWriterPP.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: GeoTriples   Source File: GeneralR2RMLCompiler.java    License: Apache License 2.0 6 votes vote down vote up
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 3
Source Project: GeoTriples   Source File: JenaModelExample.java    License: Apache License 2.0 6 votes vote down vote up
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 4
Source Project: GeoTriples   Source File: VocabularySummarizer.java    License: Apache License 2.0 6 votes vote down vote up
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 5
Source Project: GeoTriples   Source File: D2RQReader.java    License: Apache License 2.0 6 votes vote down vote up
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 Project: GeoTriples   Source File: D2RQReader.java    License: Apache License 2.0 6 votes vote down vote up
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 7
Source Project: GeoTriples   Source File: R2RMLReader.java    License: Apache License 2.0 6 votes vote down vote up
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 8
Source Project: wandora   Source File: SparqlExtractor.java    License: GNU General Public License v3.0 6 votes vote down vote up
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 9
Source Project: EventCoreference   Source File: TrigUtil.java    License: Apache License 2.0 6 votes vote down vote up
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 10
/**
 * 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 11
Source Project: GeoTriples   Source File: WP2RDFXMLWriter.java    License: Apache License 2.0 5 votes vote down vote up
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 12
Source Project: GeoTriples   Source File: VocabularySummarizer.java    License: Apache License 2.0 5 votes vote down vote up
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 13
Source Project: GeoTriples   Source File: VocabularySummarizer.java    License: Apache License 2.0 5 votes vote down vote up
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 14
Source Project: GeoTriples   Source File: VocabularySummarizer.java    License: Apache License 2.0 5 votes vote down vote up
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 15
Source Project: GeoTriples   Source File: VocabularySummarizer.java    License: Apache License 2.0 5 votes vote down vote up
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 16
Source Project: GeoTriples   Source File: PageServlet.java    License: Apache License 2.0 5 votes vote down vote up
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 17
Source Project: GeoTriples   Source File: DatasetDescriptionServlet.java    License: Apache License 2.0 5 votes vote down vote up
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 18
Source Project: GeoTriples   Source File: D2RQReader.java    License: Apache License 2.0 5 votes vote down vote up
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 19
Source Project: GeoTriples   Source File: D2RQReader.java    License: Apache License 2.0 5 votes vote down vote up
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 20
Source Project: GeoTriples   Source File: R2RMLReader.java    License: Apache License 2.0 5 votes vote down vote up
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 Project: neo4jena   Source File: Course.java    License: Apache License 2.0 5 votes vote down vote up
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 22
Source Project: SolRDF   Source File: SolRDF.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 23
Source Project: SolRDF   Source File: SolRDF.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 24
Source Project: xcurator   Source File: OpenCycOntology.java    License: Apache License 2.0 5 votes vote down vote up
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 25
Source Project: xcurator   Source File: JenaUtils.java    License: Apache License 2.0 5 votes vote down vote up
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 26
Source Project: xcurator   Source File: RdfGeneratorTest2.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 27
Source Project: xcurator   Source File: RdfGeneratorTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 28
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 29
Source Project: EventCoreference   Source File: GetEventStats.java    License: Apache License 2.0 5 votes vote down vote up
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 30
Source Project: GeoTriples   Source File: D2RQReader.java    License: Apache License 2.0 4 votes vote down vote up
private void parsePropertyBridge(PropertyBridge bridge, Resource r) {
	StmtIterator stmts;
	stmts = r.listProperties(D2RQ.column);
	while (stmts.hasNext()) {
		if (r.getProperty(RDF.type).equals(D2RQ.ObjectPropertyBridge)) {
			// Legacy
			bridge.setURIColumn(Microsyntax.parseColumn(stmts.nextStatement().getString()));
		} else {
			bridge.setColumn(Microsyntax.parseColumn(stmts.nextStatement().getString()));
		}
	}
	stmts = r.listProperties(D2RQ.pattern);
	while (stmts.hasNext()) {
		if (r.getProperty(RDF.type).equals(D2RQ.ObjectPropertyBridge)) {
			// Legacy
			bridge.setURIPattern(stmts.nextStatement().getString());
		} else {
			bridge.setPattern(stmts.nextStatement().getString());
		}
	}
	stmts = r.listProperties(D2RQ.sqlExpression);
	while (stmts.hasNext()) {
		bridge.setSQLExpression(stmts.nextStatement().getString());
	}
	stmts = r.listProperties(D2RQ.lang);
	while (stmts.hasNext()) {
		bridge.setLang(stmts.nextStatement().getString());
	}
	stmts = r.listProperties(D2RQ.datatype);
	while (stmts.hasNext()) {
		bridge.setDatatype(stmts.nextStatement().getResource().getURI());
	}
	stmts = r.listProperties(D2RQ.refersToClassMap);
	while (stmts.hasNext()) {
		Resource classMapResource = stmts.nextStatement().getResource();
		bridge.setRefersToClassMap(this.mapping.classMap(classMapResource));
	}
	stmts = r.listProperties(D2RQ.dynamicProperty);
	while (stmts.hasNext()) {
		bridge.addDynamicProperty(stmts.next().getString());
	}
	stmts = r.listProperties(D2RQ.property);
	while (stmts.hasNext()) {
		bridge.addProperty(stmts.nextStatement().getResource());
	}
	stmts = this.model.listStatements(null, D2RQ.propertyBridge, r);
	while (stmts.hasNext()) {
		bridge.addProperty(stmts.nextStatement().getSubject());
	}
	stmts = r.listProperties(D2RQ.propertyDefinitionLabel);
	while (stmts.hasNext()) {
		bridge.addDefinitionLabel(stmts.nextStatement().getLiteral());
	}
	stmts = r.listProperties(D2RQ.propertyDefinitionComment);
	while (stmts.hasNext()) {
		bridge.addDefinitionComment(stmts.nextStatement().getLiteral());
	}
	stmts = r.listProperties(D2RQ.additionalPropertyDefinitionProperty);
	while (stmts.hasNext()) {
		Resource additionalProperty = stmts.nextStatement().getResource();
		bridge.addAdditionalDefinitionProperty(additionalProperty);
	}
	stmts = r.listProperties(D2RQ.limit);
	while (stmts.hasNext()) {
	    bridge.setLimit(stmts.nextStatement().getInt());
	}
	stmts = r.listProperties(D2RQ.limitInverse);
	while (stmts.hasNext()) {
	    bridge.setLimitInverse(stmts.nextStatement().getInt());
	}
	stmts = r.listProperties(D2RQ.orderDesc);
	while (stmts.hasNext()) {
	    bridge.setOrder(stmts.nextStatement().getString(), true);
	}
	stmts = r.listProperties(D2RQ.orderAsc);
	while (stmts.hasNext()) {
	    bridge.setOrder(stmts.nextStatement().getString(), false);
	}
}