/** * Executes any sparql query. The type of the result object will vary * depending on the type of the query. If the defaultGraph is available * in this TcManages executeSparqlQuery(String, UriRef) should be used instead. * * @param query the sparql query to execute * @param defaultGraphName the ImmutableGraph to be used as default ImmutableGraph in the Sparql ImmutableGraph Store * @return the resulting ResultSet, ImmutableGraph or Boolean value */ public Object executeSparqlQuery(String query, IRI defaultGraphName) throws ParseException { return executeSparqlQuery(query, defaultGraphName, false); }
protected void activate(ComponentContext componentContext) { this.context = componentContext.getBundleContext(); try { tcManager.getGraph(Constants.CONFIG_GRAPH_URI); } catch (NoSuchEntityException nsee) { tcManager.createGraph(Constants.CONFIG_GRAPH_URI); } }
/** * Creates a new input source by querying the default triple collection manager for a graph named with the * supplied <code>graphId</code>. The supplied ID will also be set as the graph origin. * * @param graphId * the graph ID. * @throws NullPointerException * if there is no default triple collection manager available. * @throws org.apache.clerezza.rdf.core.access.NoSuchEntityException * if no such graph can be found. */ public GraphSource(IRI graphId) { this(graphId, TcManager.getInstance()); }
private Graph getOrCreatePermisionGraph() { try { return tcManager.getMGraph(permissionGraphName); } catch (NoSuchEntityException e) { return tcManager.createGraph(permissionGraphName); } }
private MGraph getConceptCacheMGraph() { MGraph conceptCacheMGraph = null; TcManager tcManager = TcManager.getInstance(); try { conceptCacheMGraph = tcManager.getMGraph(CONCEPT_CACHE_MGRAPH); } catch (NoSuchEntityException nsee) { conceptCacheMGraph = tcManager.createMGraph(CONCEPT_CACHE_MGRAPH); } return conceptCacheMGraph; }
@Override public RecipeList findRecipesByDescription(String term) { String sparql = "SELECT ?recipe " + "WHERE { ?recipe a " + Symbols.Recipe.toString() + " . " + "?recipe " + Symbols.description + " ?description . " + "FILTER (regex(?description, \"" + term + "\", \"i\"))" + "}"; Graph tripleCollection = tcManager.getGraph(new IRI(recipeIndexLocation)); RecipeList matchingRecipes = new RecipeList(); try { SelectQuery query = (SelectQuery) QueryParser.getInstance().parse(sparql); ResultSet resultSet = tcManager.executeSparqlQuery(query, tripleCollection); while (resultSet.hasNext()) { SolutionMapping solutionMapping = resultSet.next(); IRI recipeID = (IRI) solutionMapping.get("recipe"); try { Recipe recipe = getRecipe(recipeID); log.info("Found recipe {}.", recipeID.toString()); matchingRecipes.add(recipe); log.info("Found {} matching recipes.", matchingRecipes.size()); } catch (NoSuchRecipeException e) { // in this case go on in the iteration by fetching other matching recipes } catch (RecipeConstructionException e) { // in this case go on in the iteration by fetching other matching recipes } } } catch (ParseException e) { log.error("The sparql query contains errors: ", e); } return matchingRecipes; }
@Override public Graph getRefactoredDataSet(IRI uriRef) { return tcManager.getGraph(uriRef); }
if(tcManager == null){ //this will be the case if we are not in an OSGI environment tcManager = TcManager.getInstance(); this.graph = tcManager.getImmutableGraph(yardGraphUri); immutable = true; } catch(NoSuchEntityException e) { this.graph = tcManager.getGraph(yardGraphUri); immutable = false; } catch (NoSuchEntityException e) { log.info(" ... create new Graph {} for Yard {}",yardGraphUri,config.getName()); this.graph = tcManager.createGraph(yardGraphUri);
private InternetAddress getUserAddress(String user) throws MessagingException { MGraph systemGraph = tcManager.getMGraph(systemGraphUri); final String queryString = "SELECT ?email WHERE { " + "?x " + FOAF.mbox + " ?email . " + "?x " + PLATFORM.userName + " \"" + user + "\" . " + "}"; try { SelectQuery selectQuery = (SelectQuery) QueryParser.getInstance().parse(queryString); ResultSet result = tcManager.executeSparqlQuery(selectQuery, systemGraph); if (result.hasNext()) { Resource email = result.next().get("email"); String emailString = ((UriRef) email).getUnicodeString(); //TODO should add personal name (if available) as well return new InternetAddress(emailString.substring("mailto:".length())); } } catch (ParseException ex) { throw new RuntimeException(ex); } catch (AddressException ex) { throw new RuntimeException(ex); } throw new MessagingException("No address found for user " + user); } }
private LockableMGraph getConfigGraph() { return tcManager.getMGraph(Constants.CONFIG_GRAPH_URI); }
@Override public boolean removeRecipe(IRI recipeID) throws RecipeEliminationException { // remove the recipe from the TcManager try { tcManager.deleteGraph(recipeID); } catch (NoSuchEntityException e) { throw new RecipeEliminationException(e); } Graph recipeIndexGraph = tcManager.getGraph(new IRI(recipeIndexLocation)); Triple triple = new TripleImpl(recipeID, RDF.type, Symbols.Recipe); recipeIndexGraph.remove(triple); // System.out.println("Recipes: " +recipes.size()); // remove the recipe ID from in-memory list recipes.remove(recipeID); return true; }
TcProvider singleTargetTcProvider = null; if (forceFastlane) { singleTargetTcProvider = getSingleTargetTcProvider(Collections.singleton(defaultGraphName)); } else { SparqlPreParser sparqlPreParser = new SparqlPreParser(this); final Set<IRI> referencedGraphs = sparqlPreParser.getReferredGraphs(query, defaultGraphName); if ((referencedGraphs != null)) { singleTargetTcProvider = getSingleTargetTcProvider(referencedGraphs); return queryEngine.execute(this, this.getGraph(defaultGraphName), query); } else { throw new NoQueryEngineException();
public static Graph createOntology(String id, TcManager tcm) { IRI name = new IRI(id); Graph ont = tcm.createGraph(name); ont.add(new TripleImpl(name, RDF.type, OWL.Ontology)); return ont; }
public void createEnhancementGraph() throws StoreException { final UriRef graphUri = new UriRef(Constants.ENHANCEMENTS_GRAPH_URI); MGraph enhancementGraph = null; try { enhancementGraph = tcManager.getMGraph(graphUri); String filter = String.format("(%s=%s)", "graph.uri", graphUri.getUnicodeString()); ServiceReference[] sr = bundleContext.getServiceReferences(TripleCollection.class.getName(), filter); if (sr == null) { registerEnhancementGraph(graphUri, enhancementGraph); } } catch (NoSuchEntityException e) { log.debug("Creating the enhancement graph!"); enhancementGraph = tcManager.createMGraph(graphUri); registerEnhancementGraph(graphUri, enhancementGraph); } catch (InvalidSyntaxException e) { log.error("Failed to get ServiceReference for TripleCollection"); throw new StoreException("Failed to get ServiceReference for TripleCollection", e); } }
throw new RuntimeException(ex); Set<IRI> graphsToLock = referencedGraphs != null ? referencedGraphs : tcManager.listGraphs(); final DatasetGraph datasetGraph = new TcDatasetGraph(tcManager, defaultGraph); final Dataset dataset = DatasetFactory.create(datasetGraph); tc = defaultGraph; } else { tc = tcManager.getGraph(uriRef);
protected Set<TripleCollection> getImportedGraphs(TripleCollection g, boolean recursive) { Set<TripleCollection> result = new HashSet<TripleCollection>(); UriRef u = OWLUtils.guessOntologyIdentifier(g); Iterator<Triple> it = g.filter(u, OWL.imports, null); while (it.hasNext()) { Resource r = it.next().getObject(); if (r instanceof UriRef) { TripleCollection gr = TcManager.getInstance().getTriples((UriRef) r); // Avoid calls to getGraph() to save memory // if (gr instanceof Graph) result.add(/* (Graph) */gr); // else if (gr instanceof MGraph) result.add(((MGraph) gr).getGraph()); if (recursive) result.addAll(getImportedGraphs(gr, true)); } } return result; }
/** * avtivates the component and adds the enrichment-graph to the virtual * content graph. * * gets the base content-graph from tcManager and sets the permission * required to access the enrichment-graph accordingly */ protected void activate(ComponentContext context) { contentGraph = tcManager.getMGraph(Constants.CONTENT_GRAPH_URI); Collection<Permission> requiredReadPermissions = tcManager.getTcAccessController().getRequiredReadPermissions(Constants.CONTENT_GRAPH_URI); if (requiredReadPermissions.isEmpty()) { tcManager.getTcAccessController().setRequiredReadPermissionStrings( ENRICHMENT_GRAPH_URI, Collections.singleton( new TcPermission(Constants.CONTENT_GRAPH_URI_STRING, TcPermission.READ).toString() )); } else { tcManager.getTcAccessController().setRequiredReadPermissions( ENRICHMENT_GRAPH_URI, requiredReadPermissions); } cgProvider.addTemporaryAdditionGraph(ENRICHMENT_GRAPH_URI); }
@Override public Object getService(Bundle arg0, ServiceRegistration arg1) { Graph tc = new SecuredGraph(tcManager.getImmutableGraph(name), name, tcAccessController); return tc.getImmutableGraph(); }
public static MGraph createOntology(String id, TcManager tcm) { UriRef name = new UriRef(id); MGraph ont = tcm.createMGraph(name); ont.add(new TripleImpl(name, RDF.type, OWL.Ontology)); return ont; }
@Override public RecipeList findRecipesByDescription(String term) { String sparql = "SELECT ?recipe " + "WHERE { ?recipe a " + Symbols.Recipe.toString() + " . " + "?recipe " + Symbols.description + " ?description . " + "FILTER (regex(?description, \"" + term + "\", \"i\"))" + "}"; Graph tripleCollection = tcManager.getGraph(new IRI(recipeIndexLocation)); RecipeList matchingRecipes = new RecipeList(); try { SelectQuery query = (SelectQuery) QueryParser.getInstance().parse(sparql); ResultSet resultSet = tcManager.executeSparqlQuery(query, tripleCollection); while (resultSet.hasNext()) { SolutionMapping solutionMapping = resultSet.next(); IRI recipeID = (IRI) solutionMapping.get("recipe"); try { Recipe recipe = getRecipe(recipeID); log.info("Found recipe {}.", recipeID.toString()); matchingRecipes.add(recipe); log.info("Found {} matching recipes.", matchingRecipes.size()); } catch (NoSuchRecipeException e) { // in this case go on in the iteration by fetching other matching recipes } catch (RecipeConstructionException e) { // in this case go on in the iteration by fetching other matching recipes } } } catch (ParseException e) { log.error("The sparql query contains errors: ", e); } return matchingRecipes; }