private Collection<DocumentationItem> getDocItems(ImmutableGraph documentations) { Iterator<Triple> docs = documentations.filter(null, DOCUMENTATION.documentation, null); Map<IRI,DocumentationItem> uri2docItemObj = new HashMap<IRI,DocumentationItem>(); while (docs.hasNext()) { Triple docc = docs.next(); IRI docItem = (IRI) docc.getObject(); Iterator<Triple> afterDocItemsIter = documentations.filter(docItem, DOCUMENTATION.after, null); Set<IRI> afterDocItems = new HashSet<IRI>(); while (afterDocItemsIter.hasNext()) { afterDocItems.add((IRI) afterDocItemsIter.next().getObject()); } DocumentationItem docItemObj = new DocumentationItem( docItem, afterDocItems, uri2docItemObj); uri2docItemObj.put(docItem, docItemObj); } return uri2docItemObj.values(); }
@Override public Set<IRI> getNames(ImmutableGraph graph) { final HashSet<IRI> result = new HashSet<IRI>(); if (unitedDocumentations.equals(graph)) { result.add(DOCUMENTATION_GRAPH_URI); } return result; }
for(TripleMatcher m : matchers) { final Set<IRI> s = new HashSet<IRI>(); final Iterator<Triple> it = g.iterator(); while(it.hasNext()) { final Triple t = it.next();
graph.add(t1); } catch(UnsupportedOperationException uoe) { expThrown = true; graph.remove(t1); } catch(UnsupportedOperationException uoe) { expThrown = true; graph.addAll(t); } catch(UnsupportedOperationException uoe) { expThrown = true; graph.clear(); } catch(UnsupportedOperationException uoe) { expThrown = true; graph.removeAll(t); } catch(UnsupportedOperationException uoe) { expThrown = true;
@Test public void testCreateGraphWithInitialCollection() throws Exception { Triple t1 = createTestTriple(); TcProvider provider = getInstance(); ImmutableGraph graph = provider.createImmutableGraph(graphIRI, createTestTripleCollection(t1)); assertEquals(1, graph.size()); assertTrue(graph.contains(t1)); provider.deleteGraph(graphIRI); }
graph.add(t1); } catch(UnsupportedOperationException uoe) { expThrown = true; graph.remove(t1); } catch(UnsupportedOperationException uoe) { expThrown = true; graph.addAll(t); } catch(UnsupportedOperationException uoe) { expThrown = true; graph.clear(); } catch(UnsupportedOperationException uoe) { expThrown = true; graph.removeAll(t); } catch(UnsupportedOperationException uoe) { expThrown = true;
@Test public void testCreateGraphWithInitialCollection() throws Exception { Triple t1 = createTestTriple(); TcProvider provider = getInstance(); ImmutableGraph graph = provider.createImmutableGraph(graphIRI, createTestTripleCollection(t1)); assertEquals(1, graph.size()); assertTrue(graph.contains(t1)); provider.deleteGraph(graphIRI); }
public Response deleteUser(ImmutableGraph inputGraph) { Iterator<Triple> userNameTriples = inputGraph.filter(null, PLATFORM.userName, null);
private Graph getDocumentationGraph(URL docUrl, String symbolicName) { try { ImmutableGraph parsedGraph = parser.parse(docUrl.openStream(), SupportedFormat.N_TRIPLE); IRI baseUri = config.getDefaultBaseUri(); return new SimpleGraph(new UriMutatorIterator( parsedGraph.iterator(), baseUri.getUnicodeString(), symbolicName)); } catch (IOException ex) { logger.warn("Cannot parse documentation at URL: {}", docUrl); throw new RuntimeException(ex); } }
@Override public Set<IRI> getNames(ImmutableGraph graph) { //TODO: this method would require to compare the triples within the graph // because an equals check will not work with BlankNodes. Set<IRI> graphNames = new HashSet<IRI>(); for( Iterator<Triple> iterator = graphNameIndex.getGraph().iterator(); iterator.hasNext(); ) { Triple triple = iterator.next(); IRI graphName = new IRI(triple.getSubject().toString()); ImmutableGraph currentGraph = getModelGraph(graphName, false, false).getImmutableGraph(); if(graph.equals(currentGraph)){ graphNames.add(graphName); } } return graphNames; }
readLock.lock(); Iterator<Triple> changes = inputGraph.filter(null, null, Ontology.Change); .filter(changeNode, PLATFORM.userName, null).next() .getObject(); .filter(changeNode, Ontology.predicate, null).next() .getObject(); Iterator<Triple> iterator = inputGraph.filter(changeNode, Ontology.oldValue, null); .filter(changeNode, Ontology.newValue, null).next() .getObject();
@Test public void testCreateImmutableGraph() { TcProvider simpleTcmProvider = getInstance(); Graph mGraph = new SimpleGraph(); mGraph.add(new TripleImpl(uriRefA, uriRefA, uriRefA)); ImmutableGraph createdGraph = simpleTcmProvider.createImmutableGraph(uriRefA, mGraph); Iterator<Triple> iteratorInput = mGraph.iterator(); Iterator<Triple> iteratorCreated = createdGraph.iterator(); assertEquals(iteratorInput.next(), iteratorCreated.next()); assertFalse(iteratorCreated.hasNext()); try { simpleTcmProvider.createImmutableGraph(uriRefA, mGraph); assertTrue(false); } catch (EntityAlreadyExistsException e) { assertTrue(true); } simpleTcmProvider.deleteGraph(uriRefA); }
BlankNode potentialMatch = (BlankNode)potentialTriple.getObject(); final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext(); if (potentialContext.equals(context)) { removingTriples.addAll(potentialContext); unGroundedTriples.removeAll(context); BlankNode potentialMatch = (BlankNode)potentialTriple.getSubject(); final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext(); if (potentialContext.equals(context)) { removingTriples.addAll(potentialContext); unGroundedTriples.removeAll(context);
@Test public void testCreateImmutableGraph() { TcProvider simpleTcmProvider = getInstance(); Graph mGraph = new SimpleGraph(); mGraph.add(new TripleImpl(uriRefA, uriRefA, uriRefA)); ImmutableGraph createdGraph = simpleTcmProvider.createImmutableGraph(uriRefA, mGraph); Iterator<Triple> iteratorInput = mGraph.iterator(); Iterator<Triple> iteratorCreated = createdGraph.iterator(); assertEquals(iteratorInput.next(), iteratorCreated.next()); assertFalse(iteratorCreated.hasNext()); try { simpleTcmProvider.createImmutableGraph(uriRefA, mGraph); assertTrue(false); } catch (EntityAlreadyExistsException e) { assertTrue(true); } simpleTcmProvider.deleteGraph(uriRefA); }
BlankNode potentialMatch = (BlankNode)potentialTriple.getObject(); final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext(); if (potentialContext.equals(context)) { removingTriples.addAll(potentialContext); unGroundedTriples.removeAll(context); BlankNode potentialMatch = (BlankNode)potentialTriple.getSubject(); final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext(); if (potentialContext.equals(context)) { removingTriples.addAll(potentialContext); unGroundedTriples.removeAll(context);
@Override public int importConceptsFromGraph(ImmutableGraph graph, IRI conceptClass, IRI broaderProperty) throws ClassifierException { int importedCount = 0; Iterator<Triple> conceptIterator = graph.filter(null, org.apache.stanbol.enhancer.servicesapi.rdf.Properties.RDF_TYPE, conceptClass); while (conceptIterator.hasNext()) { Triple conceptTriple = conceptIterator.next(); if (!(conceptTriple.getSubject() instanceof IRI)) { continue; } IRI conceptUri = (IRI) conceptTriple.getSubject(); GraphNode node = new GraphNode(conceptUri, graph); List<String> broaderConcepts = new ArrayList<String>(); // TODO: use OWL property inference on sub-properties here instead of explicit // property filter Iterator<GraphNode> broaderIterator = node.getObjectNodes(broaderProperty); while (broaderIterator.hasNext()) { RDFTerm node2 = broaderIterator.next().getNode(); if (node2 instanceof IRI) { broaderConcepts.add(((IRI) node2).getUnicodeString()); } } addConcept(conceptUri.getUnicodeString(), broaderConcepts); importedCount++; } return importedCount; } }
@Test public void testGetImmutableGraph() { TcProvider simpleTcmProvider = getInstance(); // add Graphs Graph mGraph = new SimpleGraph(); mGraph.add(new TripleImpl(uriRefA, uriRefA, uriRefA)); simpleTcmProvider.createImmutableGraph(uriRefA, mGraph); mGraph = new SimpleGraph(); mGraph.add(new TripleImpl(uriRefA1, uriRefA1, uriRefA1)); simpleTcmProvider.createImmutableGraph(uriRefA1, mGraph); mGraph = new SimpleGraph(); mGraph.add(new TripleImpl(uriRefB, uriRefB, uriRefB)); simpleTcmProvider.createImmutableGraph(uriRefB, mGraph); mGraph = new SimpleGraph(); mGraph.add(new TripleImpl(uriRefB1, uriRefB1, uriRefB1)); simpleTcmProvider.createImmutableGraph(uriRefB1, mGraph); ImmutableGraph bGraph = simpleTcmProvider.getImmutableGraph(uriRefB); Iterator<Triple> iterator = bGraph.iterator(); assertEquals(new TripleImpl(uriRefB, uriRefB, uriRefB), iterator.next()); assertFalse(iterator.hasNext()); simpleTcmProvider.deleteGraph(uriRefA); simpleTcmProvider.deleteGraph(uriRefA1); simpleTcmProvider.deleteGraph(uriRefB); simpleTcmProvider.deleteGraph(uriRefB1); }
@Override public int importConceptsFromGraph(ImmutableGraph graph, IRI conceptClass, IRI broaderProperty) throws ClassifierException { int importedCount = 0; Iterator<Triple> conceptIterator = graph.filter(null, org.apache.stanbol.enhancer.servicesapi.rdf.Properties.RDF_TYPE, conceptClass); while (conceptIterator.hasNext()) { Triple conceptTriple = conceptIterator.next(); if (!(conceptTriple.getSubject() instanceof IRI)) { continue; } IRI conceptUri = (IRI) conceptTriple.getSubject(); GraphNode node = new GraphNode(conceptUri, graph); List<String> broaderConcepts = new ArrayList<String>(); // TODO: use OWL property inference on sub-properties here instead of explicit // property filter Iterator<GraphNode> broaderIterator = node.getObjectNodes(broaderProperty); while (broaderIterator.hasNext()) { RDFTerm node2 = broaderIterator.next().getNode(); if (node2 instanceof IRI) { broaderConcepts.add(((IRI) node2).getUnicodeString()); } } addConcept(conceptUri.getUnicodeString(), broaderConcepts); importedCount++; } return importedCount; } }
@Test public void testGetImmutableGraph() { TcProvider simpleTcmProvider = getInstance(); // add Graphs Graph mGraph = new SimpleGraph(); mGraph.add(new TripleImpl(uriRefA, uriRefA, uriRefA)); simpleTcmProvider.createImmutableGraph(uriRefA, mGraph); mGraph = new SimpleGraph(); mGraph.add(new TripleImpl(uriRefA1, uriRefA1, uriRefA1)); simpleTcmProvider.createImmutableGraph(uriRefA1, mGraph); mGraph = new SimpleGraph(); mGraph.add(new TripleImpl(uriRefB, uriRefB, uriRefB)); simpleTcmProvider.createImmutableGraph(uriRefB, mGraph); mGraph = new SimpleGraph(); mGraph.add(new TripleImpl(uriRefB1, uriRefB1, uriRefB1)); simpleTcmProvider.createImmutableGraph(uriRefB1, mGraph); ImmutableGraph bGraph = simpleTcmProvider.getImmutableGraph(uriRefB); Iterator<Triple> iterator = bGraph.iterator(); assertEquals(new TripleImpl(uriRefB, uriRefB, uriRefB), iterator.next()); assertFalse(iterator.hasNext()); simpleTcmProvider.deleteGraph(uriRefA); simpleTcmProvider.deleteGraph(uriRefA1); simpleTcmProvider.deleteGraph(uriRefB); simpleTcmProvider.deleteGraph(uriRefB1); }