Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a helper method to process XML results returned by a SPARQL endpoint #19

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@ public void saveRDFNTriple(IRDFStore store, String fileName)
public IStringMatrix sparqlRemote(String url, String SPARQL)
throws BioclipseException;

@Recorded
@PublishedMethod(
params = "String queryResults, String originalQuery",
methodSummary = "Parses the XML-formatted SPARQL end point results into an IStringMatrix. "
+ "The originalQuery is used to determine prefixes."
)
public IStringMatrix processSPARQLXML(byte[] queryResults, String originalQuery)
throws BioclipseException;

@Recorded
@PublishedMethod(
params = "String url, String SPARQL",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFactory;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
Expand All @@ -64,6 +65,7 @@
import com.hp.hpl.jena.shared.NoReaderForLangException;
import com.hp.hpl.jena.shared.PrefixMapping;
import com.hp.hpl.jena.shared.SyntaxError;
import com.hp.hpl.jena.shared.impl.PrefixMappingImpl;
import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP;
import com.hp.hpl.jena.util.iterator.Filter;

Expand Down Expand Up @@ -503,6 +505,31 @@ public StringMatrix sparqlRemote(
return table;
}

public StringMatrix processSPARQLXML(
byte[] queryResults, String originalQuery, IProgressMonitor monitor) {
if (monitor == null) monitor = new NullProgressMonitor();

monitor.beginTask("Processing XML results returned by a SPARQL end point..", 100);
PrefixMapping prefixMap = null;
if (originalQuery != null) {
try {
Query query = QueryFactory.create(originalQuery);
prefixMap = query.getPrefixMapping();
} catch (Exception exception) {
// could not parse the query for namespaces
prefixMap = new PrefixMappingImpl();
}
}
monitor.worked(20);

// now the Jena part
ResultSet results = ResultSetFactory.fromXML(new ByteArrayInputStream(queryResults));
StringMatrix table = StringMatrixHelper.convertIntoTable(prefixMap, results);
monitor.worked(80);

return table;
}

public IRDFStore sparqlConstructRemote(
String serviceURL,
String sparqlQueryString, IProgressMonitor monitor)
Expand Down