Java Code Examples for com.hp.hpl.jena.rdf.model.StmtIterator#next()

The following examples show how to use com.hp.hpl.jena.rdf.model.StmtIterator#next() . 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: GeneralR2RMLCompiler.java    From GeoTriples with 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 2
Source File: R2RMLReader.java    From GeoTriples with 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 3
Source File: VocabularySummarizer.java    From GeoTriples with 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 4
Source File: R2RMLReader.java    From GeoTriples with 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 5
Source File: JenaUtils.java    From xcurator with 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;
}