com.hp.hpl.jena.sparql.core.DatasetGraph Java Examples

The following examples show how to use com.hp.hpl.jena.sparql.core.DatasetGraph. 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: RDFFileManager.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
public static void initializeDataset(String serviceDesc) {
	// if (clean) {
	deleteDir(new File(databaseDirectory));
	if (!(new File(databaseDirectory)).mkdir()) {
		System.out.println("can not create working directory" + databaseDirectory);
	}
	DatasetGraph datasettdb = TDBFactory.createDatasetGraph(databaseDirectory);
	dataset = DatasetImpl.wrap(datasettdb);
	loadOntology(dataset);
	Model serviceBase = FileManager.get().loadModel(datasetDirectory + serviceDesc);
	dataset.getDefaultModel().add(ModelFactory.createOntologyModel(ontoSpec, serviceBase));
	// } else
	// dataset = TDBFactory.createDataset(databaseDirectory);
}
 
Example #2
Source File: RdfBulkUpdateRequestHandler.java    From SolRDF with Apache License 2.0 5 votes vote down vote up
@Override
public void load( 
		final SolrQueryRequest request, 
		final SolrQueryResponse response,
		final ContentStream stream, 
		final UpdateRequestProcessor processor) throws Exception {
	
	final PipedRDFIterator<Quad> iterator = new PipedRDFIterator<Quad>();
	final StreamRDF inputStream = new PipedQuadsStream(iterator);
	
	executor.submit(new Runnable() {
		@Override
		public void run() {
			try {
				RDFDataMgr.parse(
						inputStream, 
						stream.getStream(), 
						RDFLanguages.contentTypeToLang(stream.getContentType()));
			} catch (final IOException exception) {
				throw new SolrException(ErrorCode.SERVER_ERROR, exception);
			}					
		}
	});
	
	final DatasetGraph dataset = new LocalDatasetGraph(request, response);
	while (iterator.hasNext()) {
		dataset.add(iterator.next());
	}									
}
 
Example #3
Source File: RdfBulkUpdateRequestHandler.java    From SolRDF with Apache License 2.0 5 votes vote down vote up
@Override
public void load(
		final SolrQueryRequest request, 
		final SolrQueryResponse response,
		final ContentStream stream, 
		final UpdateRequestProcessor processor) throws Exception {
	
	final PipedRDFIterator<Triple> iterator = new PipedRDFIterator<Triple>();
	final StreamRDF inputStream = new PipedTriplesStream(iterator);
	
	executor.submit(new Runnable() {
		@Override
		public void run() {
			try {
				RDFDataMgr.parse(
						inputStream, 
						stream.getStream(), 
						RDFLanguages.contentTypeToLang(stream.getContentType()));
			} catch (final IOException exception) {
				throw new SolrException(ErrorCode.SERVER_ERROR, exception);
			}					
		}
	});
		
	// Graph Store Protocol indicates the target graph URI separately.
	// So the incoming Content-type here is one that maps "Triples Loader" but
	// the indexed tuple could be a Quad.
	final String graphUri = request.getParams().get(Names.GRAPH_URI_ATTRIBUTE_NAME);
	
	final DatasetGraph dataset = new LocalDatasetGraph(request, response, null, null);
	final Graph defaultGraph = graphUri == null 
			? dataset.getDefaultGraph() 
			: dataset.getGraph(NodeFactory.createURI(graphUri));
	while (iterator.hasNext()) {
		defaultGraph.add(iterator.next());
	}		
}
 
Example #4
Source File: Sparql11UpdateRdfDataLoader.java    From SolRDF with Apache License 2.0 5 votes vote down vote up
/**
 * Executes a given {@link UpdateRequest} against the given {@link DatasetGraph}.
 * 
 * @param updateRequest the update request.
 * @param datasetGraph the dataset graph.
 * @param graphUris the target graphs (optional).
 */
void execute(final UsingList list, final String updateRequests, final DatasetGraph datasetGraph) {
	try {
		UpdateAction.parseExecute(
				list, 
				datasetGraph, 
				new ByteArrayInputStream(updateRequests.getBytes("UTF-8")));		
	} catch (final Exception exception) {	
		final String message = MessageFactory.createMessage(
				MessageCatalog._00099_INVALID_UPDATE_QUERY, 
				updateRequests);
		LOGGER.error(message, exception);
		throw new SolrException(ErrorCode.BAD_REQUEST, message);
	}	
}
 
Example #5
Source File: ProcessEventObjectsStream.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
static public String matchSingleTmx(Node tmx, DatasetGraph g, Model m){
    String sq="";
    if (g.contains(null, tmx, typeNode, instantNode)) { // One Instant
        sq += "?ev <http://semanticweb.cs.vu.nl/2009/11/sem/hasTime> ?t . ?t a <http://www.w3.org/TR/owl-time#Instant> . ";
        for (Iterator<Quad> iter = g.find(null, tmx, specificTimeNode, null); iter.hasNext(); ) {
            Quad q = iter.next();
            sq += "?t <http://www.w3.org/TR/owl-time#inDateTime> <" + q.asTriple().getObject() + "> . ";
        }
    } else { // One Interval

        String intervalQuery = "SELECT ?begin ?end WHERE { <" + tmx + ">  <http://www.w3.org/TR/owl-time#hasBeginning> ?begin ; <http://www.w3.org/TR/owl-time#hasEnd> ?end . }";

        Query inQuery = QueryFactory.create(intervalQuery);

        // Create a single execution of this query, apply to a model
        // which is wrapped up as a Dataset
        QueryExecution inQexec = QueryExecutionFactory.create(inQuery, m);

        try {
            // Assumption: it’s a SELECT query.
            ResultSet inrs = inQexec.execSelect();
            // The order of results is undefined.
            for (; inrs.hasNext(); ) {
                QuerySolution evrb = inrs.nextSolution();
                // Get title - variable names do not include the ’?’
                String begin = evrb.get("begin").toString();
                String end = evrb.get("end").toString();

                String unionQuery = "{ ?ev <http://semanticweb.cs.vu.nl/2009/11/sem/hasTime> ?t . ?t a <http://www.w3.org/TR/owl-time#Interval> . ?t <http://www.w3.org/TR/owl-time#hasBeginning> <" + begin + "> ; <http://www.w3.org/TR/owl-time#hasEnd> <" + end + "> . } ";
                unionQuery += "UNION ";
                unionQuery += "{ ?ev <http://semanticweb.cs.vu.nl/2009/11/sem/hasEarliestBeginTimeStamp> ?t1 . ?t1 a <http://www.w3.org/TR/owl-time#Instant> . ?t1 <http://www.w3.org/TR/owl-time#inDateTime> <" + begin + "> . ?ev <http://semanticweb.cs.vu.nl/2009/11/sem/hasEarliestEndTimeStamp> ?t2 . ?t2 a <http://www.w3.org/TR/owl-time#Instant> . ?t2 <http://www.w3.org/TR/owl-time#inDateTime> <" + end + "> . } ";
                sq += unionQuery;
            }
        } finally {
            inQexec.close();
        }
    }
    return sq;
}
 
Example #6
Source File: ProcessEventObjectsStream.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
private static void inferIdentityRelations(String sparqlQuery, boolean matchILI, boolean matchLemma, boolean matchMultiple, int iliSize, Node eventId, DatasetGraph g) {
    if (matchILI || matchLemma) {
        sparqlQuery += "GROUP BY ?ev";
    }
    HttpAuthenticator authenticator = new SimpleAuthenticator(user, pass.toCharArray());
    QueryExecution x = QueryExecutionFactory.sparqlService(serviceEndpoint, sparqlQuery, authenticator);
    ResultSet resultset = x.execSelect();
    int threshold;
    while (resultset.hasNext()) {
        QuerySolution solution = resultset.nextSolution();
        if (matchILI || matchLemma) {
            if (matchILI)
                threshold = conceptMatchThreshold;
            else
                threshold=phraseMatchThreshold;

            if (matchMultiple) {
                //System.out.println(solution);
                if (checkIliLemmaThreshold(iliSize, solution.get("conceptcount").asLiteral().getInt(), solution.get("myconceptcount").asLiteral().getInt(), threshold)) {
                    insertIdentity(g, eventId, solution.get("ev").asNode());
                }
            } else {
                if (checkIliLemmaThreshold(1, solution.get("conceptcount").asLiteral().getInt(), 1, threshold)) {
                    insertIdentity(g, eventId, solution.get("ev").asNode());
                }
            }
        } else {
            insertIdentity(g, eventId, solution.get("ev").asNode());
        }
    }
}
 
Example #7
Source File: AutoReloadableDataset.java    From GeoTriples with Apache License 2.0 4 votes vote down vote up
public DatasetGraph asDatasetGraph() {
	// check already done by servlets before getting the graph
	//checkMappingFileChanged();
	return datasetGraph;
}
 
Example #8
Source File: SparqlSearchComponent.java    From SolRDF with Apache License 2.0 2 votes vote down vote up
/**
 * Creates an appropriate {@link DatasetGraph} for this SolRDF instance.
 * 
 * @param request the current Solr request
 * @param response the current Solr response.
 * @param parser the Query parser associated with the current request.
 * @param consumer a {@link GraphEventConsumer} for this query cycle.
 * @return an appropriate {@link DatasetGraph} for this SolRDF instance.
 */
DatasetGraph datasetGraph(final SolrQueryRequest request, final SolrQueryResponse response, final QParser parser, final GraphEventConsumer consumer) {
	return request.getCore().getCoreDescriptor().getCoreContainer().isZooKeeperAware() 
			? new CloudDatasetGraph(request, response, server)
			: new LocalDatasetGraph(request, response, parser, consumer);
}
 
Example #9
Source File: Sparql11UpdateRdfDataLoader.java    From SolRDF with Apache License 2.0 2 votes vote down vote up
/**
 * Creates an appropriate {@link DatasetGraph} for this SolRDF instance.
 * 
 * @param request the current Solr request
 * @param response the current Solr response.
 * @param parser the Query parser associated with the current request.
 * @param consumer a {@link GraphEventConsumer} for this query cycle.
 * @return an appropriate {@link DatasetGraph} for this SolRDF instance.
 */
DatasetGraph datasetGraph(final SolrQueryRequest request, final SolrQueryResponse response) {
	return CLUSTER != null 
			? new CloudDatasetGraph(request, response, CLUSTER)
			: new LocalDatasetGraph(request, response);
}
 
Example #10
Source File: ProcessEventObjectsStream.java    From EventCoreference with Apache License 2.0 2 votes vote down vote up
private static void insertIdentity (DatasetGraph g, Node e1, Node e2){
    g.add(identityGraphNode, e1, identityNode, e2);

}