org.openrdf.query.QueryResultHandlerException Java Examples

The following examples show how to use org.openrdf.query.QueryResultHandlerException. 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: SPARQLInferenceTest.java    From neo4j-sparql-extension with GNU General Public License v3.0 6 votes vote down vote up
private QueryResult runQuery()
		throws IOException, QueryEvaluationException,
		       QueryResultParseException, TupleQueryResultHandlerException,
			   QueryResultHandlerException {
	TestResultHandler noninf = new TestResultHandler();
	TestResultHandler actual = new TestResultHandler();
	TestResultHandler expect = new TestResultHandler();
	parser.setQueryResultHandler(expect);
	parser.parseQueryResult(getResource(expected));
	nonInfQuery.evaluate(noninf);
	query.evaluate(actual);
	Multiset<BindingSet> noninfset = noninf.getSolutions();
	Multiset<BindingSet> expectset = expect.getSolutions();
	Multiset<BindingSet> actualset = actual.getSolutions();
	return new QueryResult(expectset, actualset, noninfset);
}
 
Example #2
Source File: SPARQLInferenceTest.java    From neo4j-sparql-extension with GNU General Public License v3.0 6 votes vote down vote up
@Before
public void before()
		throws RepositoryException, IOException, RDFParseException,
		       MalformedQueryException, QueryResultParseException,
			   QueryResultHandlerException {
	repo = new SailRepository(new MemoryStore());
	repo.initialize();
	conn = repo.getConnection();
	vf = conn.getValueFactory();
	conn.add(getResource(data), "file://", RDFFormat.TURTLE);
	SPARQLResultsXMLParserFactory factory =
			new SPARQLResultsXMLParserFactory();
	parser = factory.getParser();
	parser.setValueFactory(vf);
	List<Rule> rules;
	rules = Rules.fromOntology(getResource(data));
	QueryRewriter rewriter = new QueryRewriter(conn, rules);
	query = (TupleQuery) rewriter.rewrite(QueryLanguage.SPARQL, queryString);
	nonInfQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
	System.out.println("== QUERY (" + this.name + ") ==");
	System.out.println(nonInfQuery);
	System.out.println("== REWRITTEN QUERY (" + this.name + ") ==");
	System.out.println(query);
}
 
Example #3
Source File: SPARQLJSONWriterBase.java    From database with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void handleLinks(List<String> linkUrls)
	throws QueryResultHandlerException
{
	try {
		if (!documentOpen) {
			startDocument();
		}

		if (!headerOpen) {
			startHeader();
		}

		jg.writeArrayFieldStart("link");
		for (String nextLink : linkUrls) {
			jg.writeString(nextLink);
		}
		jg.writeEndArray();
	}
	catch (IOException e) {
		throw new QueryResultHandlerException(e);
	}
}
 
Example #4
Source File: SPARQLJSONWriterBase.java    From database with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void endHeader()
	throws QueryResultHandlerException
{
	if (!headerComplete) {
		try {
			jg.writeEndObject();

			if (tupleVariablesFound) {
				// Write results
				jg.writeObjectFieldStart("results");

				jg.writeArrayFieldStart("bindings");
			}

			headerComplete = true;
		}
		catch (IOException e) {
			throw new QueryResultHandlerException(e);
		}
	}
}
 
Example #5
Source File: SPARQLJSONWriterBase.java    From database with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void startHeader()
	throws QueryResultHandlerException
{
	if (!documentOpen) {
		startDocument();
	}

	if (!headerOpen) {
		try {
			// Write header
			jg.writeObjectFieldStart("head");

			headerOpen = true;
		}
		catch (IOException e) {
			throw new QueryResultHandlerException(e);
		}
	}
}
 
Example #6
Source File: SPARQLInferenceTest.java    From neo4j-sparql-extension with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void subset()
		throws QueryEvaluationException, TupleQueryResultHandlerException,
		       IOException, QueryResultParseException,
			   QueryResultHandlerException {
	QueryResult q = this.runQuery();
	assertTrue(
		q.getNonInferred() + " should be a subset of " + q.getActual(),
		Multisets.containsOccurrences(
			q.getActual(),
			q.getNonInferred()
		));
}
 
Example #7
Source File: BigdataSPARQLResultsJSONWriterForConstruct.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startRDF() throws RDFHandlerException {
    try {
        writer.startDocument();
        writer.startHeader();
        writer.startQueryResult(Arrays.asList(new String[] {
                "subject", "predicate", "object", "context"
        }));
        writer.endHeader();
    } catch (QueryResultHandlerException e) {
        throw new RDFHandlerException(e);
    }
}
 
Example #8
Source File: BigdataSPARQLResultsJSONWriterForConstruct.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handleNamespace(String prefix, String uri)
        throws RDFHandlerException {
    try {
        writer.handleNamespace(prefix, uri);
    } catch (QueryResultHandlerException e) {
        throw new RDFHandlerException(e);
    }
}
 
Example #9
Source File: SPARQLJSONWriterBase.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handleBoolean(boolean value)
	throws QueryResultHandlerException
{
	if (!documentOpen) {
		startDocument();
	}

	if (!headerOpen) {
		startHeader();
	}

	if (!headerComplete) {
		endHeader();
	}

	if (tupleVariablesFound) {
		throw new QueryResultHandlerException("Cannot call handleBoolean after startQueryResults");
	}

	try {
		if (value) {
			jg.writeBooleanField("boolean", Boolean.TRUE);
		}
		else {
			jg.writeBooleanField("boolean", Boolean.FALSE);
		}

		endDocument();
	}
	catch (IOException e) {
		throw new QueryResultHandlerException(e);
	}
}
 
Example #10
Source File: SPARQLJSONWriterBase.java    From database with GNU General Public License v2.0 5 votes vote down vote up
protected void writeValue(Value value)
	throws IOException, QueryResultHandlerException
{
	jg.writeStartObject();

	if (value instanceof URI) {
		jg.writeStringField("type", "uri");
		jg.writeStringField("value", ((URI)value).toString());
	}
	else if (value instanceof BNode) {
		jg.writeStringField("type", "bnode");
		jg.writeStringField("value", ((BNode)value).getID());
	}
	else if (value instanceof Literal) {
		Literal lit = (Literal)value;

		// TODO: Implement support for
		// BasicWriterSettings.RDF_LANGSTRING_TO_LANG_LITERAL here
		if (lit.getLanguage() != null) {
			jg.writeObjectField("xml:lang", lit.getLanguage());
		}
		// TODO: Implement support for
		// BasicWriterSettings.XSD_STRING_TO_PLAIN_LITERAL here
		if (lit.getDatatype() != null) {
			jg.writeObjectField("datatype", lit.getDatatype().stringValue());
		}

		jg.writeObjectField("type", "literal");

		jg.writeObjectField("value", lit.getLabel());
	}
	else {
		throw new TupleQueryResultHandlerException("Unknown Value object type: " + value.getClass());
	}
	jg.writeEndObject();
}
 
Example #11
Source File: SPARQLJSONWriterBase.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startDocument()
	throws QueryResultHandlerException
{
	if (!documentOpen) {
		documentOpen = true;
		headerOpen = false;
		headerComplete = false;
		tupleVariablesFound = false;
		firstTupleWritten = false;
		linksFound = false;

		if (getWriterConfig().get(BasicWriterSettings.PRETTY_PRINT)) {
			// By default Jackson does not pretty print, so enable this unless
			// PRETTY_PRINT setting
			// is disabled
			jg.useDefaultPrettyPrinter();
		}

		try {
			if (getWriterConfig().isSet(BasicQueryWriterSettings.JSONP_CALLBACK)) {
				// SES-1019 : Write the callbackfunction name as a wrapper for
				// the results here
				String callbackName = getWriterConfig().get(BasicQueryWriterSettings.JSONP_CALLBACK);
				jg.writeRaw(callbackName);
				jg.writeRaw("(");
			}
			jg.writeStartObject();
		}
		catch (IOException e) {
			throw new QueryResultHandlerException(e);
		}
	}
}
 
Example #12
Source File: TestResultHandler.java    From neo4j-sparql-extension with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void handleLinks(List<String> linkUrls) throws QueryResultHandlerException {
}
 
Example #13
Source File: TestResultHandler.java    From neo4j-sparql-extension with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void handleBoolean(boolean value) throws QueryResultHandlerException {
}
 
Example #14
Source File: SPARQLJSONWriterBase.java    From database with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void handleNamespace(String prefix, String uri)
	throws QueryResultHandlerException
{
	// Ignored by SPARQLJSONWriterBase
}
 
Example #15
Source File: SPARQLJSONWriterBase.java    From database with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void handleStylesheet(String stylesheetUrl)
	throws QueryResultHandlerException
{
	// Ignore, as JSON does not support stylesheets
}
 
Example #16
Source File: BigdataSPARQLResultsJSONWriter.java    From database with GNU General Public License v2.0 4 votes vote down vote up
protected void writeSid(final BigdataBNode sid) 
        throws IOException, QueryResultHandlerException {
    
    jg.writeStartObject();

    jg.writeStringField("type", BigdataSPARQLResultsJSONParser.SID);
    
    final BigdataStatement stmt = sid.getStatement();
    
    jg.writeFieldName(BigdataSPARQLResultsJSONParser.SUBJECT);
    writeValue(stmt.getSubject());
    
    jg.writeFieldName(BigdataSPARQLResultsJSONParser.PREDICATE);
    writeValue(stmt.getPredicate());
    
    jg.writeFieldName(BigdataSPARQLResultsJSONParser.OBJECT);
    writeValue(stmt.getObject());

    if (stmt.getContext() != null) {
        jg.writeFieldName(BigdataSPARQLResultsJSONParser.CONTEXT);
        writeValue(stmt.getContext());
    }
    
    jg.writeEndObject();
    
}
 
Example #17
Source File: BigdataSPARQLResultsJSONWriter.java    From database with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void writeValue(final Value value) throws IOException,
        QueryResultHandlerException {
    
    if (value instanceof BigdataBNode &&
            ((BigdataBNode) value).isStatementIdentifier()) {
        
        writeSid((BigdataBNode) value);
        
    } else {
        
        super.writeValue(value);
        
    }
    
}
 
Example #18
Source File: SPARQLJSONParserBase.java    From database with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void parseQueryResult(InputStream in)
	throws IOException, QueryResultParseException, QueryResultHandlerException
{
	parseQueryResultInternal(in, true, true);
}
 
Example #19
Source File: BigdataSPARQLResultsJSONParserForConstruct.java    From database with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void handleLinks(List<String> linkUrls)
        throws QueryResultHandlerException {
    // do nothing
}
 
Example #20
Source File: BigdataSPARQLResultsJSONParserForConstruct.java    From database with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void handleBoolean(boolean value) throws QueryResultHandlerException {
    // do nothing
}
 
Example #21
Source File: BackgroundTupleResult.java    From database with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void handleLinks(List<String> arg0)
        throws QueryResultHandlerException {
    // no-op
}
 
Example #22
Source File: BackgroundTupleResult.java    From database with GNU General Public License v2.0 2 votes vote down vote up
@Override
public void handleBoolean(boolean arg0) throws QueryResultHandlerException {

    throw new UnsupportedOperationException("Cannot handle boolean results");
    
}
 
Example #23
Source File: QueryEvaluation.java    From CostFed with GNU Affero General Public License v3.0 2 votes vote down vote up
@Override
public void handleLinks(List<String> arg0) throws QueryResultHandlerException {
	
}
 
Example #24
Source File: QueryEvaluation.java    From CostFed with GNU Affero General Public License v3.0 2 votes vote down vote up
@Override
public void handleBoolean(boolean arg0) throws QueryResultHandlerException {
	
}