use of org.apache.jena.rdf.model.Model in project jena by apache.
the class T_TDBWriteTransaction method run.
public static void run(String location) {
if (false) {
Journal journal = Journal.create(Location.create(location));
JournalControl.print(journal);
journal.close();
}
//String location = args[0]; // + "/" + UUID.randomUUID().toString();
//String baseGraphName = "com.ibm.test.graphNamePrefix.";
long totalExecTime = 0L;
long size = 0;
Dataset dataset = TDBFactory.createDataset(location);
Dataset dataset1 = TDBFactory.createDataset(location);
if (bracketWithReader)
dataset1.begin(ReadWrite.READ);
for (int i = 0; i < TOTAL; i++) {
List<String> lastProcessedUris = new ArrayList<>();
for (int j = 0; j < 10 * i; j++) {
String lastProcessedUri = "http://test.net/xmlns/test/1.0/someUri" + j;
lastProcessedUris.add(lastProcessedUri);
}
//Dataset dataset = TDBFactory.createDataset(location);
//String graphName = baseGraphName + i;
long t = System.currentTimeMillis();
try {
dataset.begin(ReadWrite.WRITE);
Model m = dataset.getDefaultModel();
m.removeAll();
Resource subject = m.createResource(INDEX_INFO_SUBJECT);
Property predicate = m.createProperty(TIMESTAMP_PREDICATE);
m.addLiteral(subject, predicate, System.currentTimeMillis());
predicate = m.createProperty(URI_PREDICATE);
for (String uri : lastProcessedUris) {
m.add(subject, predicate, m.createResource(uri));
}
predicate = m.createProperty(VERSION_PREDICATE);
m.addLiteral(subject, predicate, 1.0);
size += m.size() + 1;
predicate = m.createProperty(INDEX_SIZE_PREDICATE);
m.addLiteral(subject, predicate, size);
dataset.commit();
} catch (Throwable e) {
dataset.abort();
throw new RuntimeException(e);
} finally {
dataset.end();
long writeOperationDuration = System.currentTimeMillis() - t;
totalExecTime += writeOperationDuration;
System.out.println("Write operation " + i + " took " + writeOperationDuration + "ms");
}
}
if (bracketWithReader)
dataset1.end();
System.out.println("All " + TOTAL + " write operations wrote " + size + " triples and took " + totalExecTime + "ms");
}
use of org.apache.jena.rdf.model.Model in project jena by apache.
the class T_TransSystem method describeWithAbort.
public static int describeWithAbort(String queryStr, DatasetGraph dsg, long abortTime) {
int counter = 0;
Query query = QueryFactory.create(queryStr, Syntax.syntaxARQ);
try (QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.wrap(dsg))) {
qExec.setTimeout(abortTime);
Model model = qExec.execDescribe();
//ResultSet rs = qExec.execSelect() ;
for (Iterator<Statement> stmIterator = model.listStatements(); stmIterator.hasNext(); ) {
stmIterator.next();
counter++;
}
return counter;
}
}
use of org.apache.jena.rdf.model.Model in project jena by apache.
the class ResultSetFactory method result.
/**
* Read in any kind of result kind (result set, boolean, graph)
*/
public static SPARQLResult result(String filenameOrURI, ResultsFormat format) {
if (format == null)
format = ResultsFormat.guessSyntax(filenameOrURI);
if (format == null) {
Log.warn(ResultSet.class, "Null format - defaulting to XML");
format = ResultsFormat.FMT_RS_XML;
}
if (format.equals(ResultsFormat.FMT_TEXT)) {
Log.error(ResultSet.class, "Can't read a text result set");
throw new ResultSetException("Can't read a text result set");
}
if (format.equals(ResultsFormat.FMT_RS_XML) || format.equals(ResultsFormat.FMT_RS_JSON) || format.equals(ResultsFormat.FMT_RS_TSV) || format.equals(ResultsFormat.FMT_RS_CSV)) {
InputStream in = null;
try {
in = FileManager.get().open(filenameOrURI);
if (in == null)
throw new NotFoundException(filenameOrURI);
} catch (NotFoundException ex) {
throw new NotFoundException("File not found: " + filenameOrURI);
}
SPARQLResult x = null;
if (format.equals(ResultsFormat.FMT_RS_JSON))
return JSONInput.make(in, GraphFactory.makeDefaultModel());
else if (format.equals(ResultsFormat.FMT_RS_XML))
return XMLInput.make(in, GraphFactory.makeDefaultModel());
else if (format.equals(ResultsFormat.FMT_RS_TSV)) {
ResultSet rs = TSVInput.fromTSV(in);
return new SPARQLResult(rs);
} else if (format.equals(ResultsFormat.FMT_RS_CSV)) {
ResultSet rs = CSVInput.fromCSV(in);
return new SPARQLResult(rs);
} else if (format.equals(ResultsFormat.FMT_RS_BIO)) {
ResultSet rs = BIOInput.fromBIO(in);
return new SPARQLResult(rs);
}
}
if (ResultsFormat.isRDFGraphSyntax(format)) {
Model model = FileManager.get().loadModel(filenameOrURI);
return new SPARQLResult(model);
}
Log.error(ResultSet.class, "Unknown result set syntax: " + format);
return null;
}
use of org.apache.jena.rdf.model.Model in project jena by apache.
the class QueryExecUtils method outputResultSet.
@SuppressWarnings("deprecation")
public static void outputResultSet(ResultSet results, Prologue prologue, ResultsFormat outputFormat) {
// Proper ResultSet formats.
Lang lang = ResultsFormat.convert(outputFormat);
if (lang != null) {
ResultSetMgr.write(System.out, results, lang);
System.out.flush();
return;
}
// Old way.
boolean done = false;
if (prologue == null)
prologue = new Prologue(globalPrefixMap);
if (outputFormat.equals(ResultsFormat.FMT_UNKNOWN))
outputFormat = ResultsFormat.FMT_TEXT;
if (outputFormat.equals(ResultsFormat.FMT_NONE) || outputFormat.equals(ResultsFormat.FMT_COUNT)) {
int count = ResultSetFormatter.consume(results);
if (outputFormat.equals(ResultsFormat.FMT_COUNT)) {
System.out.println("Count = " + count);
}
done = true;
}
if (outputFormat.equals(ResultsFormat.FMT_RDF_XML) || outputFormat.equals(ResultsFormat.FMT_RDF_N3) || outputFormat.equals(ResultsFormat.FMT_RDF_TTL)) {
Model m = RDFOutput.encodeAsModel(results);
m.setNsPrefixes(prologue.getPrefixMapping());
m.setNsPrefix("rs", ResultSetGraphVocab.getURI());
RDFDataMgr.write(System.out, m, Lang.TURTLE);
done = true;
}
if (outputFormat.equals(ResultsFormat.FMT_RS_XML)) {
ResultSetFormatter.outputAsXML(System.out, results);
done = true;
}
if (outputFormat.equals(ResultsFormat.FMT_RS_JSON)) {
ResultSetFormatter.outputAsJSON(System.out, results);
done = true;
}
if (outputFormat.equals(ResultsFormat.FMT_RS_SSE)) {
ResultSetFormatter.outputAsSSE(System.out, results, prologue);
done = true;
}
if (outputFormat.equals(ResultsFormat.FMT_TEXT)) {
ResultSetFormatter.out(System.out, results, prologue);
done = true;
}
if (outputFormat.equals(ResultsFormat.FMT_TUPLES)) {
PlainFormat pFmt = new PlainFormat(System.out, prologue);
ResultSetApply a = new ResultSetApply(results, pFmt);
a.apply();
done = true;
}
if (outputFormat.equals(ResultsFormat.FMT_RS_CSV)) {
ResultSetFormatter.outputAsCSV(System.out, results);
done = true;
}
if (outputFormat.equals(ResultsFormat.FMT_RS_TSV)) {
ResultSetFormatter.outputAsTSV(System.out, results);
done = true;
}
if (outputFormat.equals(ResultsFormat.FMT_RS_BIO)) {
ResultSetFormatter.outputAsBIO(System.out, results);
done = true;
}
if (!done)
System.err.println("Unknown format request: " + outputFormat);
results = null;
System.out.flush();
}
use of org.apache.jena.rdf.model.Model in project jena by apache.
the class QueryExecUtils method doDescribeQuery.
private static void doDescribeQuery(Prologue prologue, QueryExecution qe, ResultsFormat outputFormat) {
if (outputFormat == null || outputFormat == ResultsFormat.FMT_UNKNOWN)
outputFormat = ResultsFormat.FMT_RDF_TTL;
Model r = qe.execDescribe();
writeModel(prologue, r, outputFormat);
}
Aggregations