private Set<IRI> getSeeAlsoObjectUris(GraphNode node) { Set<IRI> result = new HashSet<IRI>(); Lock l = node.readLock(); l.lock(); try { Iterator<RDFTerm> objects = node.getObjects(RDFS.seeAlso); while (objects.hasNext()) { RDFTerm next = objects.next(); if (next instanceof IRI) { result.add((IRI)next); } } } finally { l.unlock(); } return result; }
private Set<IRI> getSeeAlsoObjectUris(GraphNode node) { Set<IRI> result = new HashSet<IRI>(); Lock l = node.readLock(); l.lock(); try { Iterator<RDFTerm> objects = node.getObjects(RDFS.seeAlso); while (objects.hasNext()) { RDFTerm next = objects.next(); if (next instanceof IRI) { result.add((IRI)next); } } } finally { l.unlock(); } return result; }
/** * Checks wether this node has the given property with the given value. * If the given value is null, then it is checked if this node has the * specified property regardless of its value. * * @param property * @param object * @return true if the node represented by this object is the subject of a * statement with the given prediate and object, false otherwise */ public boolean hasProperty(IRI property, RDFTerm object) { Lock l = readLock(); l.lock(); try { Iterator<RDFTerm> objects = getObjects(property); if (object == null) { return objects.hasNext(); } while (objects.hasNext()) { if (objects.next().equals(object)) { return true; } } return false; } finally { l.unlock(); } }
/** * Checks wether this node has the given property with the given value. * If the given value is null, then it is checked if this node has the * specified property regardless of its value. * * @param property * @param object * @return true if the node represented by this object is the subject of a * statement with the given prediate and object, false otherwise */ public boolean hasProperty(IRI property, RDFTerm object) { Lock l = readLock(); l.lock(); try { Iterator<RDFTerm> objects = getObjects(property); if (object == null) { return objects.hasNext(); } while (objects.hasNext()) { if (objects.next().equals(object)) { return true; } } return false; } finally { l.unlock(); } }
/** * Count the number of triples in the underlying triple-collection * with this node as object and a specified property as predicate. * * @param property the property to be examined * @return the number of triples in the underlying triple-collection * which meet the specified condition */ public int countSubjects(IRI property) { Lock l = readLock(); l.lock(); try { return countTriples(graph.filter(null, property, resource)); } finally { l.unlock(); } }
private void followInversePaths(Resource resource, List<UriRef> pathToIndexedResource, List<Resource> list) { if (pathToIndexedResource.isEmpty()) { list.add(resource); } else { GraphNode node = new GraphNode(resource, this.baseGraph); Lock lock = node.readLock(); lock.lock(); try { Iterator<NonLiteral> predecessors = node.getSubjects(pathToIndexedResource.get(0)); List<UriRef> tail = pathToIndexedResource.subList(1, pathToIndexedResource.size()); while (predecessors.hasNext()) { followInversePaths(predecessors.next(), tail, list); } } finally { lock.unlock(); } //throw new RuntimeException("modification of indirect properties not yet supported") } }
private void getPathResults(GraphNode node, List<UriRef> properties, List<String> list) { if (properties.size() == 1) { //being a facet property or not is irrelevant for the result list.addAll(new PropertyHolder(properties.get(0), false).value(node)); } else { Lock lock = node.readLock(); lock.lock(); try { Iterator<GraphNode> iter = node.getObjectNodes(properties.get(0)); while (iter.hasNext()) { getPathResults(iter.next(), properties.subList(1, properties.size()), list); } } finally { lock.unlock(); } } } }
/** * Count the number of triples in the underlying triple-collection * with this node as object and a specified property as predicate. * * @param property the property to be examined * @return the number of triples in the underlying triple-collection * which meet the specified condition */ public int countSubjects(IRI property) { Lock l = readLock(); l.lock(); try { return countTriples(graph.filter(null, property, resource)); } finally { l.unlock(); } }
@Override protected List<String> value(GraphNode node) { List<String> list = new ArrayList<String>(); Lock lock = node.readLock(); lock.lock(); try { Iterator<Resource> iter = node.getObjects(this.property); while(iter.hasNext()) { Resource resource = iter.next(); if(resource instanceof Literal) { list.add(((Literal)resource).getLexicalForm()); } else if(resource instanceof UriRef) { list.add(((UriRef) resource).getUnicodeString()); } } } finally { lock.unlock(); } return list; }
private boolean isBaseRole(BlankNodeOrIRI role) { Graph systemGraph = getSystemGraph(); GraphNode roleNode = new GraphNode(role, systemGraph); Lock readLock = roleNode.readLock(); readLock.lock(); try { return roleNode.hasProperty(RDF.type, PERMISSION.BaseRole); } finally { readLock.unlock(); } }
/** * Remove index definitions for the specified RDF type. * * @param rdfType the RDF type */ public void deleteDefinition(UriRef rdfType) { GraphNode node = new GraphNode(rdfType, definitionGraph); Set<GraphNode> toDelete = new HashSet<GraphNode>(); node.readLock().lock(); try { Iterator<GraphNode> iter = node.getSubjectNodes(CRIS.indexedType); while (iter.hasNext()) { toDelete.add(iter.next()); } } finally { node.readLock().unlock(); } node.writeLock().lock(); try { for (GraphNode graphNode : toDelete) { graphNode.deleteNodeContext(); } } finally { node.writeLock().unlock(); } }
@Override public IRI run() { GraphNode platformInstance = getPlatformInstance(); Lock l = platformInstance.readLock(); l.lock(); try { Iterator<RDFTerm> triples = platformInstance.getObjects(PLATFORM.defaultBaseUri); if (triples.hasNext()) { return (IRI) triples.next(); } else { String port = context.getProperty("org.osgi.service.http.port"); if (port == null) { port = DEFAULT_PORT; } if (port.equals("80")) { return new IRI("http://localhost/"); } return new IRI("http://localhost:" + port + "/"); } } finally { l.unlock(); } } });
private void indexNamedResource(UriRef uriRef, IndexWriter writer) throws IOException { Term term = new Term(URI_FIELD_NAME, uriRef.getUnicodeString()); writer.deleteDocuments(term); //the reindexing might be caused by the removal of a type statement GraphNode node = new GraphNode(uriRef, this.baseGraph); List<UriRef> types = new ArrayList<UriRef>(); Lock lock = node.readLock(); lock.lock(); try { Iterator<Resource> resources = node.getObjects(RDF.type); while (resources.hasNext()) { Resource res = resources.next(); if (res instanceof UriRef) { types.add((UriRef) res); } } } finally { lock.unlock(); } for (UriRef type : types) { if (type2IndexedProperties.containsKey(type)) { Document doc = resourceToDocument(uriRef, type); doc.add(new Field(URI_FIELD_NAME, uriRef.getUnicodeString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); writer.addDocument(doc); } } }
/** * The context of a node are the triples containing a node * as subject or object and recursively the context of the b-nodes in any * of these statements. * * The triples in the ImmutableGraph returned by this method contain the same bnode * instances as in the original graph. * * @return the context of the node represented by the instance */ public ImmutableGraph getNodeContext() { Lock l = readLock(); l.lock(); try { final HashSet<RDFTerm> dontExpand = new HashSet<RDFTerm>(); dontExpand.add(resource); if (resource instanceof IRI) { return getContextOf((IRI) resource, dontExpand).getImmutableGraph(); } return getContextOf(resource, dontExpand).getImmutableGraph(); } finally { l.unlock(); } }
/** * The context of a node are the triples containing a node * as subject or object and recursively the context of the b-nodes in any * of these statements. * * The triples in the ImmutableGraph returned by this method contain the same bnode * instances as in the original graph. * * @return the context of the node represented by the instance */ public ImmutableGraph getNodeContext() { Lock l = readLock(); l.lock(); try { final HashSet<RDFTerm> dontExpand = new HashSet<RDFTerm>(); dontExpand.add(resource); if (resource instanceof IRI) { return getContextOf((IRI) resource, dontExpand).getImmutableGraph(); } return getContextOf(resource, dontExpand).getImmutableGraph(); } finally { l.unlock(); } }
@Override public void reCreateIndex() { processDefinitions(); List<NonLiteral> instances = new ArrayList<NonLiteral>(); for (UriRef indexedType : type2IndexedProperties.keySet()) { //lock necessary? Lock lock = new GraphNode(indexedType, this.baseGraph).readLock(); lock.lock(); try { Iterator<Triple> iter = this.baseGraph.filter(null, RDF.type, indexedType); while (iter.hasNext()) { instances.add(iter.next().getSubject()); } } finally { lock.unlock(); } } logger.debug("instances " + instances.size()); IndexWriter writer = luceneTools.getIndexWriter(true); try { writer.deleteAll(); } catch (IOException ex) { throw new RuntimeException(ex); } for (NonLiteral instance : instances) { indexResource(instance, writer); } luceneTools.commitChanges(); }
GraphNode node = new GraphNode(resource, e.getGraph()); List<UriRef> types = new ArrayList<UriRef>(); Lock lock = node.readLock(); lock.lock(); try {