private Graph getExpandedContext(GraphNode node) { final Graph result = new SimpleGraph(node.getNodeContext()); final Set<RDFTerm> expandedResources = new HashSet<RDFTerm>(); expandedResources.add(node.getNode()); while (true) { Set<RDFTerm> additionalExpansionRes = getAdditionalExpansionResources(result); additionalExpansionRes.removeAll(expandedResources); if (additionalExpansionRes.size() == 0) { return result; } for (RDFTerm resource : additionalExpansionRes) { final GraphNode additionalNode = new GraphNode(resource, node.getGraph()); result.addAll(additionalNode.getNodeContext()); expandedResources.add(resource); } } }
private GraphNode addConceptCacheNode(MGraph conceptCacheMGraph) { GraphNode conceptCacheGraphNode = new GraphNode(new BNode(), conceptCacheMGraph); conceptCacheGraphNode.addProperty(RDF.type, CONCEPTS.ConceptCache); conceptCacheGraphNode.addProperty(CONCEPTS.sparqlEndPoint, sparqlEndPoint); if (defaultGraph != null) { conceptCacheGraphNode.addProperty(CONCEPTS.defaultGraph, defaultGraph); } return conceptCacheGraphNode; }
private void removeCachedConcepts(GraphNode conceptCacheEntryGraphNode) { Iterator<Resource> searchResults = conceptCacheEntryGraphNode.getObjects(CONCEPTS.searchResult); while (searchResults.hasNext()) { Resource concept = searchResults.next(); GraphNode conceptGraphNode = new GraphNode(concept, conceptCacheEntryGraphNode.getGraph()); conceptGraphNode.deleteProperties(OWL.sameAs); conceptGraphNode.deleteProperties(RDFS.comment); conceptGraphNode.deleteProperties(SKOS.prefLabel); conceptGraphNode.deleteProperties(RDF.type); } conceptCacheEntryGraphNode.deleteProperties(CONCEPTS.searchResult); conceptCacheEntryGraphNode.deleteProperties(DC.date); conceptCacheEntryGraphNode.deleteProperties(CONCEPTS.searchTerm); conceptCacheEntryGraphNode.deleteProperties(RDF.type); }
private void updateProperty(GraphNode node, IRI predicate, RDFTerm object) { node.deleteProperties(predicate); node.addProperty(predicate, object); }
private void addAvailableRoles(GraphNode result) { Iterator<NonLiteral> roles = userManager.getRoles(); while (roles.hasNext()) { GraphNode role = new GraphNode(roles.next(), systemGraph); result.addProperty(USERMANAGER.role, role.getNode()); addCustomPropertiesOfRole(role, result); } }
/** * Provides the node in the system graph corresponding to rdf:type Role * * @return Role class node */ public GraphNode getRoleType() { return new GraphNode(PERMISSION.Role, systemGraph); }
/** * Returns a language uri of a language which has a label containing the * specified languageName. The label itself is in the language specified through * inLanguage. If inLanguage is null, then all labels of a language of searched. * If no language was found in the <http://www.lingvoj.org/lingvoj> * graph, then null is returned. The returned uri can be used to * add the language to Clerezza over the addLanguage()-method in this class. * @return a language uris */ public UriRef getLanguage(String languageName, Language inLanguage) { Graph lingvojGraph = getLingvojGraph(); Iterator<Triple> languages = lingvojGraph.filter(null, RDFS.isDefinedBy, null); while (languages.hasNext()) { GraphNode languageNode = new GraphNode((UriRef) languages.next().getSubject(), lingvojGraph); Iterator<Resource> labels = languageNode.getObjects(RDFS.label); while (labels.hasNext()) { PlainLiteral label = (PlainLiteral) labels.next(); if (label.getLanguage().equals(inLanguage) || inLanguage == null) { if (label.getLexicalForm().contains(languageName)) { return (UriRef) languageNode.getNode(); } } } } return null; }
private Graph getLanguageContext(NonLiteral langUri) { Graph lingvojRdf = getLingvojGraph(); GraphNode languageNode = new GraphNode(langUri, lingvojRdf); return languageNode.getNodeContext(); }
GraphNode node = new GraphNode(uri, cgProvider.getContentGraph()); node.deleteProperties(DCTERMS.subject); if(concepts != null) { for (String subject : concepts) { node.addProperty(DCTERMS.subject, new UriRef(subject));
@Override public GraphNode getUserGraphNode(final String name) { Graph systemGraph = getSystemGraph(); BlankNodeOrIRI user = getUserByUserName(name); if (user != null) { GraphNode userNodeInSystemGraph = new GraphNode(getUserByUserName(name), systemGraph); Graph copiedUserContext = new SimpleGraph(userNodeInSystemGraph.getNodeContext()); return new GraphNode(userNodeInSystemGraph.getNode(), copiedUserContext); } else { return null; } }
GraphNode userGraphNode = new GraphNode(user, systemGraph); Lock writeLock = userGraphNode.writeLock(); writeLock.lock(); try { userGraphNode.deleteProperties(SIOC.has_function); addRolesToUser(assignedRoles, (BlankNodeOrIRI) userGraphNode.getNode());
@Override public RuntimeException run(){ try { final FileOutputStream fileOutputStream = new FileOutputStream("/tmp/broken-list.nt"); final GraphNode graphNode = new GraphNode(listRDFTerm, tc); Serializer.getInstance().serialize(fileOutputStream, graphNode.getNodeContext(), SupportedFormat.N_TRIPLE); fileOutputStream.flush(); logger.warn("GraphNode: " + graphNode); final Iterator<IRI> properties = graphNode.getProperties(); while (properties.hasNext()) { logger.warn("available: " + properties.next()); } return new RuntimeException("broken list " + listRDFTerm, e); } catch (Exception ex) { return new RuntimeException(ex); } } });
@GET public GraphNode entry(@Context UriInfo uriInfo) throws IOException { AccessController.checkPermission(new LoggingManagerAccessPermission()); TrailingSlash.enforcePresent(uriInfo); SimpleMGraph resultMGraph = new SimpleMGraph(); GraphNode result = new GraphNode(new BNode(), resultMGraph); result.addPropertyValue(LOGGING.loggingConfig, getPropertiesAsString()); result.addProperty(RDF.type, PLATFORM.HeadedPage); result.addProperty(RDF.type, LOGGING.LoggingConfigPage); return result; }
private List<VirtualProperty> getVirtualPropertyList(GraphNode r, List<VirtualProperty> vPropertyList) { List<Resource> rdfList = getPropertyList(r); for (Resource childPropertyResource : rdfList) { vPropertyList.add(asVirtualProperty(new GraphNode(childPropertyResource, r.getGraph()), vPropertyList)); } return vPropertyList; }
/** * Returns a iterator containing all objects of the triples where this * graph node is the subject and has the specified property. The objects * are returned as <code>GraphNode</code>s. * * @param property * @return */ public Iterator<GraphNode> getObjectNodes(IRI property) { final Iterator<RDFTerm> objects = this.getObjects(property); return new Iterator<GraphNode>() { @Override public boolean hasNext() { return objects.hasNext(); } @Override public GraphNode next() { RDFTerm object = objects.next(); return new GraphNode(object, graph); } @Override public void remove() { objects.remove(); } }; }
private Set<IRI> expand(GraphNode node, Set<IRI> alreadyVisited, int recursion) { Set<IRI> rdfSeeAlsoTargets = getSeeAlsoObjectUris(node); Set<IRI> result = new HashSet<IRI>(); result.addAll(rdfSeeAlsoTargets); recursion++; if (recursion > 0) { rdfSeeAlsoTargets.removeAll(alreadyVisited); alreadyVisited.addAll(rdfSeeAlsoTargets); for (IRI target : rdfSeeAlsoTargets) { try { result.addAll(expand(new GraphNode(node.getNode(), tcManager.getGraph(target)), alreadyVisited, recursion)); } catch (NoSuchEntityException e) { //ignore } } } return result; }
LanguageDescription(GraphNode resource) { this.resource = resource; Literal iso1Literal = null; TripleCollection configGraph = resource.getGraph(); if (configGraph instanceof LockableMGraph) { LockableMGraph lockableConfigGraph = (LockableMGraph)configGraph; Lock readLock = lockableConfigGraph.getLock().readLock(); readLock.lock(); try { iso1Literal = (Literal) resource.getObjects(LINGVOJ.iso1).next(); } finally { readLock.unlock(); } } else { iso1Literal = (Literal) resource.getObjects(LINGVOJ.iso1).next(); } if (iso1Literal == null) { throw new RuntimeException("No iso1 code for " +resource.getNode()); } String iso1 = iso1Literal.getLexicalForm(); this.language = new Language(iso1); }
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); } } }
private void deleteScript(UriRef scriptUri) { MGraph contentGraph = cgProvider.getContentGraph(); contentHandler.remove(scriptUri); GraphNode scriptNode = new GraphNode(scriptUri, contentGraph); scriptNode.deleteProperty(RDF.type, SCRIPT.Script); scriptNode.deleteProperties(DCTERMS.title); scriptNode.deleteProperties(SCRIPT.scriptLanguage); scriptNode.deleteProperties(SCRIPT.scriptLanguageVersion); scriptNode.deleteProperties(SCRIPT.producedType); }