com.hp.hpl.jena.query.ReadWrite Java Examples

The following examples show how to use com.hp.hpl.jena.query.ReadWrite. 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: AutoReloadableDataset.java    From GeoTriples with Apache License 2.0 4 votes vote down vote up
public void begin(ReadWrite readWrite) {
	throw new UnsupportedOperationException("Read-only dataset");
}
 
Example #2
Source File: DBPediaCandidateType.java    From uncc2014watsonsim with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Find the possible lexical types of a name.
 * tag("New York") for example might be:
 *  {"populated place", "place", "municipality"}..
 */
public List<String> viaDBPedia(String text) {
	/*
	 * ABOUT THE QUERY
	 * ===============
	 * Most of these results are not really excellent.
	 * The recall is pretty high but the precision is low because it
	 * matches every name that _contains_ the candidate answer.
	 * 
	 * So, we should probably trim the results to the most popular names.
	 * 
	 * BUT many queries have thousands of names so this will probably be
	 * slow. Meaning we probably need to compromise or develop our own
	 * solution.
	 * 
	 * ABOUT THE RESULTS
	 * =================
	 * A lot of the results are generic, like "place". And "city" is also
	 * a place, so it may just be inadequately tagged. We probably need
	 * some graph algorithm to help with this.
	 * Some results have synonyms. "country" is a real tag, but "nation" is
	 * not. WordNet can help with this.
	 * 
	 */

	rdf.begin(ReadWrite.READ);
	List<String> types = new ArrayList<>();
	try (QueryExecution qe = QueryExecutionFactory.create(getQuery(text), 
			rdf.getDefaultModel())) {
		ResultSet rs = qe.execSelect();
		while (rs.hasNext()) {
			QuerySolution s = rs.next();
			RDFNode node = s.get("?kind");
			if (node == null) {}
			else if (node.isLiteral())
				types.add(node.asLiteral().getLexicalForm().toLowerCase());
			else if (node.isResource())
				types.add(node.asResource().getLocalName().toLowerCase());
		}
	} finally {
		rdf.end();
	}

	return types;
}