Java Code Examples for com.hp.hpl.jena.rdf.model.NodeIterator#hasNext()

The following examples show how to use com.hp.hpl.jena.rdf.model.NodeIterator#hasNext() . 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: Mapping.java    From xcurator with Apache License 2.0 6 votes vote down vote up
public static Set<String> getAllTypes(Model model, String typePrefix) {
    Resource rootResource = model.createResource(typePrefix);

    com.hp.hpl.jena.rdf.model.Property classProperty = model.createProperty("http://dblab.cs.toronto.edu/project/xcurator/0.1#classes");
    Bag classBag = model.createBag("http://dblab.cs.toronto.edu/project/xcurator/0.1#classBag");
    model.add(rootResource, classProperty, classBag);

    Set<String> ret = new HashSet<String>();

    NodeIterator iterator = classBag.iterator();
    while (iterator.hasNext()) {
        Resource resource = (Resource) iterator.next();
        ret.add(resource.getURI());
    }

    return ret;
}
 
Example 2
Source File: OntologyBean.java    From LodView with MIT License 6 votes vote down vote up
private String getSingleValue(String preferredLanguage, Resource IRI, String prop, String defaultValue) {
	NodeIterator iter = model.listObjectsOfProperty(IRI, model.createProperty(prop));
	String result = defaultValue;
	boolean betterTitleMatch = false;
	while (iter.hasNext()) {
		RDFNode node = iter.nextNode();
		Literal l = node.asLiteral();
		//System.out.println(IRI + " " + preferredLanguage + " --> " + l.getLanguage() + " --> " + l.getLexicalForm());
		if (!betterTitleMatch && (result.equals(defaultValue) || l.getLanguage().equals("en") || l.getLanguage().equals(preferredLanguage))) {
			if (preferredLanguage.equals(l.getLanguage())) {
				betterTitleMatch = true;
			}
			result = l.getLexicalForm();
		}

	}
	return result;
}
 
Example 3
Source File: Misc.java    From LodView with MIT License 5 votes vote down vote up
private static Integer countFathers(String value, int i, Model model) {
	NodeIterator iter = model.listObjectsOfProperty(model.createResource(value), model.createProperty("http://www.w3.org/2000/01/rdf-schema#subClassOf"));
	while (iter.hasNext()) {
		RDFNode node = iter.next();
		return countFathers(node.toString(), ++i, model);
	}
	return i;
}
 
Example 4
Source File: ConfigurationBean.java    From LodView with MIT License 5 votes vote down vote up
private Map<String, String> populateColorPairMatcher() {
	Map<String, String> result = new HashMap<String, String>();
	ResIterator iter = confModel.listSubjectsWithProperty(confModel.createProperty(confModel.getNsPrefixURI("conf"), "hasColorPair"));
	while (iter.hasNext()) {
		Resource res = iter.next();
		NodeIterator values = confModel.listObjectsOfProperty(res, confModel.createProperty(confModel.getNsPrefixURI("conf"), "hasColorPair"));
		while (values.hasNext()) {
			RDFNode node = values.next();
			result.put(res.toString(), node.toString());
			break;
		}
	}
	return result;
}
 
Example 5
Source File: ConfigurationBean.java    From LodView with MIT License 5 votes vote down vote up
private String getSingleConfValue(String prop, String defaultValue) {
	NodeIterator iter = confModel.listObjectsOfProperty(confModel.createProperty(confModel.getNsPrefixURI("conf"), prop));
	while (iter.hasNext()) {
		RDFNode node = iter.next();
		return node.toString();
	}
	return defaultValue;
}
 
Example 6
Source File: ConfigurationBean.java    From LodView with MIT License 5 votes vote down vote up
private List<String> getMultiConfValue(String prop) {
	List<String> result = new ArrayList<String>();
	NodeIterator iter = confModel.listObjectsOfProperty(confModel.createProperty(confModel.getNsPrefixURI("conf"), prop));
	while (iter.hasNext()) {
		RDFNode node = iter.next();
		result.add(node.toString());
	}
	return result;
}
 
Example 7
Source File: ConceptImpl.java    From semanticMDR with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ObjectClass getParentConcept() {
	NodeIterator l = this.listPropertyValues(RDFS.subClassOf);

	while (l.hasNext()) {
		RDFNode res = l.nextNode();
		if (res.canAs(OntClass.class)) {
			OntClass ontClass = res.as(OntClass.class);
			if (ontClass.hasSuperClass(mdrDatabase.getVocabulary().Concept)) {
				return new ConceptImpl(res.asResource(), mdrDatabase);
			}
		}
	}
	return null;
}
 
Example 8
Source File: Parser.java    From r2rml-parser with Apache License 2.0 4 votes vote down vote up
public LinkedList<LogicalTableView> findLogicalTableViews() {
	LinkedList<LogicalTableView> results = new LinkedList<LogicalTableView>();
	Property sqlQuery = mapModel.getProperty(rrNs + "sqlQuery");
	ResIterator iter = mapModel.listSubjectsWithProperty(sqlQuery);
	while (iter.hasNext()) {
	    Resource r = iter.nextResource();
	    NodeIterator iter2 = mapModel.listObjectsOfProperty(r, sqlQuery);
	    while (iter2.hasNext()) { //should only have one
	    	RDFNode rn = iter2.next();
	    	LogicalTableView logicalTableView = new LogicalTableView();
	    	logicalTableView.setUri(r.getURI());
	    	String query = rn.asLiteral().toString();
	    	//Windows standard line separator is "\r\n"--a carriage-return followed by a linefeed. The regex below matches any number of either of the two characters
	    	query = query.replaceAll("[\r\n]+", " ");
	    	if (query.indexOf(';') != -1) query = query.replace(';', ' ');
	    	
	    	log.info("Testing query: <" + r.getURI() + "> with value: " + query);
	    	db.testQuery(query);
	    	
	    	SelectQuery selectQuery = new SelectQuery(query, properties);

	    	//if the dump is incremental, add an order by to ensure results are retrieved in the same order
	    	if (properties.containsKey("jena.jena.storeOutputModelUsingTdb")
	    		&& properties.getProperty("jena.jena.storeOutputModelUsingTdb").contains("false")
	    		&& properties.containsKey("default.incremental")
	    		&& properties.getProperty("default.incremental").contains("true")) {
	    		String q = selectQuery.getQuery();
	    		if (q.toLowerCase().indexOf("order by") == -1) {
	    			String fieldName = selectQuery.getFields().get(0).getName();
	    			int as = fieldName.toLowerCase().indexOf(" as ");
	    			if (as > -1) {
	    				fieldName = fieldName.substring(0, as);
		    			q += " order by " + fieldName;
	    				selectQuery.setQuery(q);
	    				log.info("Added ORDER BY to query that now is: " + q);
	    			}
	    		}
	    	}
	    	
	    	logicalTableView.setSelectQuery(selectQuery);
	    	results.add(logicalTableView);
	    }
	}
	return results;
}