org.apache.clerezza.commons.rdf.Graph类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(157)

本文整理了Java中org.apache.clerezza.commons.rdf.Graph类的一些代码示例,展示了Graph类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph类的具体详情如下:
包路径:org.apache.clerezza.commons.rdf.Graph
类名称:Graph

Graph介绍

暂无

代码示例

代码示例来源:origin: org.apache.clerezza/platform.documentation

/**
 * Adds triples that point from the bundle resource to its documentations.
 *
 * @param bundle
 * @param docGraph
 */
private void addAdditionalTriples(Bundle bundle, Graph docGraph) {
  IRI bundleUri = new IRI(bundle.getLocation());
  Triple triple = new TripleImpl(bundleUri, RDF.type, OSGI.Bundle);
  docGraph.add(triple);
  Iterator<Triple> titledContents = docGraph.filter(null, RDF.type,
      DISCOBITS.TitledContent);
  Set<Triple> newTriples = new HashSet<Triple>();
  for (Iterator<Triple> it = titledContents; it.hasNext();) {
    BlankNodeOrIRI titledContent = it.next().getSubject();
    if (docGraph.filter(null, DISCOBITS.holds, titledContent).hasNext()) {
      continue;
    }
    triple = new TripleImpl(bundleUri, DOCUMENTATION.documentation,
        titledContent);
    newTriples.add(triple);
  }
  docGraph.addAll(newTriples);
}

代码示例来源:origin: org.apache.clerezza/rdf.core.test

@Test
public void testRemoveAllTriples() {
  Graph graph = getEmptyGraph();
  Assert.assertEquals(0, graph.size());
  graph.add(new TripleImpl(uriRef1, uriRef2, uriRef3));
  graph.add(new TripleImpl(uriRef2, uriRef3, uriRef4));
  Assert.assertEquals(2, graph.size());
  graph.clear();
  Assert.assertEquals(0, graph.size());
}

代码示例来源:origin: org.apache.clerezza/rdf.core

@Override
public ImmutableGraph getImmutableGraph() {
  return this.triples.getImmutableGraph();
}

代码示例来源:origin: org.apache.clerezza/platform.config

private BlankNodeOrIRI getPlatformInstanceRDFTerm() {
  Lock l = systemGraph.getLock().readLock();
  l.lock();
  try {
    Iterator<Triple> instances = systemGraph.filter(null, RDF.type, PLATFORM.Instance);
    if (!instances.hasNext()) {
      throw new RuntimeException("No Platform:Instance in system graph.");
    }
    return instances.next().getSubject();
  } finally {
    l.unlock();
  }
}

代码示例来源:origin: org.apache.clerezza/rdf.core

private void removeExistingRequiredReadPermissions(IRI GraphUri,
    Graph permissionMGraph) {
  try {
    Triple t = permissionMGraph.filter(GraphUri, readPermissionListProperty, null).next();
    RDFTerm list = t.getObject();
    removeList((BlankNodeOrIRI) list, permissionMGraph);
    permissionMGraph.remove(t);
  } catch (NoSuchElementException e) {
    //There was no existing to remove
  }
}

代码示例来源:origin: apache/stanbol

void removeMapping(OWLOntologyID ontologyReference) {
  Iterator<Triple> it = graph.filter(buildResource(ontologyReference), MAPS_TO_GRAPH_URIREF, null);
  // I expect a concurrent modification exception here, but we can deal with it later.
  while (it.hasNext())
    graph.remove(it.next());
}

代码示例来源:origin: org.apache.clerezza/rdf.core

/**
 * Set the set of permissions required for read access to a triple-collection, if
 * the set is non-empty the default TCPermisson is no longer required.
 *
 * @param GraphUri
 * @param permissionDescriptions
 */
public void setRequiredReadPermissionStrings(IRI GraphUri,
    Collection<String> permissionDescriptions) {
  readPermissionCache.remove(GraphUri);
  final Graph permissionMGraph = getOrCreatePermisionGraph();
  Lock l = permissionMGraph.getLock().writeLock();
  l.lock();
  try {
    removeExistingRequiredReadPermissions(GraphUri, permissionMGraph);
    final BlankNodeOrIRI permissionList = createList(permissionDescriptions.iterator(), permissionMGraph);
    permissionMGraph.add(new TripleImpl(GraphUri,
        readPermissionListProperty, permissionList));
  } finally {
    l.unlock();
  }
}

代码示例来源:origin: org.apache.clerezza/platform.usermanager

Graph systemGraph = getSystemGraph();
Literal javaPermEntry = new PlainLiteralImpl(permissionString);
Lock readLock = systemGraph.getLock().readLock();
readLock.lock();
try {
  Iterator<Triple> javaPermTriples = systemGraph.filter(null,
      PERMISSION.javaPermissionEntry, javaPermEntry);
  if (javaPermTriples.hasNext()) {
    return javaPermTriples.next().getSubject();
  readLock.unlock();
Lock writeLock = systemGraph.getLock().writeLock();
writeLock.lock();
try {
  BlankNode result = new BlankNode();
  systemGraph.add(new TripleImpl(result,
      PERMISSION.javaPermissionEntry, javaPermEntry));
  return result;

代码示例来源:origin: apache/stanbol

@PUT
@Path("users/{username}")
@Consumes(SupportedFormat.TURTLE)
public Response createUser(@Context UriInfo uriInfo, @PathParam("username") String userName, ImmutableGraph inputGraph) {
  Lock writeLock = systemGraph.getLock().writeLock();
  writeLock.lock();
  systemGraph.addAll(inputGraph);
  writeLock.unlock();
  UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
  URI createdResource = uriBuilder.replacePath("/user-management/users/" + userName).build();
  return Response.created(createdResource).build();
}

代码示例来源:origin: org.apache.clerezza/platform.usermanager

private void deletePermissionEntriesOfARole(BlankNodeOrIRI role,
    String id, List<String> permissionEntries) {
  AccessController.checkPermission(new SecurityPermission("getPolicy"));
  if (role == null) {
    logger.debug("Cannot delete permissions: {} does not exist", id);
    return;
  }
  if (permissionEntries.isEmpty()) {
    return;
  }
  Graph systemGraph = getSystemGraph();
  Lock writeLock = systemGraph.getLock().writeLock();
  writeLock.lock();
  try {
    for (String permissionEntry : permissionEntries) {
      BlankNodeOrIRI permission = getPermissionOfAJavaPermEntry(permissionEntry);
      systemGraph.remove(new TripleImpl(role, PERMISSION.hasPermission,
          permission));
    }
  } finally {
    writeLock.unlock();
  }
  //refresh the policy so it will recheck the permissions
  Policy.getPolicy().refresh();
}

代码示例来源:origin: org.apache.clerezza/rdf.core.test

@Override
public Iterator<Triple> filter(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
  LockChecker.checkIfReadLocked(lock);
  readLock.lock();
  try {
    return new LockingIteratorForTesting(wrapped.filter(subject, predicate, object), lock);
  } finally {
    readLock.unlock();
  }
}

代码示例来源:origin: apache/stanbol

/**
 * @return the readLock or <code>null</code>if no read lock is needed
 */
private Lock readLockGraph() {
  final Lock readLock;
  readLock = graph.getLock().readLock();
  readLock.lock();
  return readLock;
}
/**

代码示例来源:origin: apache/stanbol

/**
 * Internally used to create Representations for URIs
 * @param uri the uri
 * @param check if <code>false</code> than there is no check if the URI
 *     refers to a RDFTerm in the graph that is of type {@link #REPRESENTATION}
 * @return the Representation
 */
protected final Representation getRepresentation(IRI uri, boolean check) {
  final Lock readLock = readLockGraph();
  try {
    if(!check || isRepresentation(uri)){
      Graph nodeGraph = createRepresentationGraph(uri, graph);
      //Remove the triple internally used to represent an empty Representation
      // ... this will only remove the triple if the Representation is empty
      //     but a check would take longer than the this call
      nodeGraph.remove(new TripleImpl(uri,MANAGED_REPRESENTATION,TRUE_LITERAL));
      return ((RdfValueFactory)getValueFactory()).createRdfRepresentation(uri, nodeGraph);
    } else {
      return null; //not found
    }
  } finally {
    if(readLock != null){
      readLock.unlock();
    }
  }
}
/**

代码示例来源:origin: org.apache.clerezza/rdf.utils

/**
 * @return a ReadLock if the underlying ImmutableGraph is a LockableGraph it returns its lock, otherwise null
 */
public Lock readLock() {
    return getGraph().getLock().readLock();
}

代码示例来源:origin: org.apache.clerezza/rdf.utils

/**
   *
   * @return
   */
  public Lock writeLock() {

      return (getGraph()).getLock().writeLock();

  }
}

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.ontologymanager.multiplexer.clerezza

private void attachScopeImportsClerezza(Graph target, org.semanticweb.owlapi.model.IRI prefix) {
  IRI iri = new IRI(prefix + _id);
  String scopePrefix = prefix.toString();
  scopePrefix = scopePrefix.substring(0, scopePrefix.lastIndexOf("/" + shortName + "/")) + "/ontology/";
  for (String scopeID : attachedScopes) {
    IRI physIRI = new IRI(scopePrefix + scopeID);
    target.add(new TripleImpl(iri, OWL.imports, physIRI));
  }
}

代码示例来源:origin: org.apache.clerezza/rdf.core.test

@Test
public void testUseTypedLiterals() {
  Graph graph = getEmptyGraph();
  Assert.assertEquals(0, graph.size());
  Literal value = new TypedLiteralImpl("<elem>value</elem>",xmlLiteralType);
  final TripleImpl triple1 = new TripleImpl(uriRef1, uriRef2, value);
  graph.add(triple1);
  Iterator<Triple> tripleIter = graph.filter(uriRef1, uriRef2, null);
  Assert.assertTrue(tripleIter.hasNext());
  RDFTerm gotValue = tripleIter.next().getObject();
  Assert.assertEquals(value, gotValue);
}

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.ontologymanager.multiplexer.clerezza

void mapLocator(org.semanticweb.owlapi.model.IRI locator, IRI graphName) {
  if (graphName == null) throw new IllegalArgumentException("A null graph name is not allowed.");
  // Null locator is a legal argument, will remove all locator mappings from the supplied graph
  Set<Triple> remove = new HashSet<Triple>();
  for (Iterator<Triple> nodes = graph.filter(graphName, null, null); nodes.hasNext();) {
    Triple t = nodes.next();
    // isOntology |= RDF.type.equals(t.getPredicate()) && OWL.Ontology.equals(t.getObject());
    if (RETRIEVED_FROM_URIREF.equals(t.getPredicate())) remove.add(t);
  }
  graph.removeAll(remove);
  if (locator != null) {
    Literal litloc = LiteralFactory.getInstance().createTypedLiteral(
      new IRI(locator.toString()));
    graph.add(new TripleImpl(graphName, RETRIEVED_FROM_URIREF, litloc));
  }
}

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.ontologymanager.multiplexer.clerezza

OWLOntologyID getReverseMapping(IRI graphName) {
  // Logical mappings first.
  Iterator<Triple> it = graph.filter(null, MAPS_TO_GRAPH_URIREF, graphName);
  while (it.hasNext()) {
    RDFTerm obj = it.next().getSubject();
    if (obj instanceof IRI) return buildPublicKey((IRI) obj);
  }
  Literal litloc = LiteralFactory.getInstance().createTypedLiteral(
    new IRI(graphName.getUnicodeString()));
  // Logical mappings failed, try physical mappings.
  it = graph.filter(null, RETRIEVED_FROM_URIREF, litloc);
  while (it.hasNext()) {
    RDFTerm subj = it.next().getSubject();
    if (subj instanceof IRI) return buildPublicKey((IRI) subj);
  }
  return null;
}

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.ontologymanager.multiplexer.clerezza

Set<OWLOntologyID> getVersions(org.semanticweb.owlapi.model.IRI ontologyIri) {
  if (ontologyIri == null) throw new IllegalArgumentException("Cannot get versions for a null IRI.");
  Set<OWLOntologyID> keys = new HashSet<OWLOntologyID>();
  LiteralFactory lf = LiteralFactory.getInstance();
  Literal iri = lf.createTypedLiteral(new IRI(ontologyIri.toString()));
  // Exclude aliases.
  for (Iterator<Triple> it = graph.filter(null, HAS_ONTOLOGY_IRI_URIREF, iri); it.hasNext();) {
    RDFTerm sub = it.next().getSubject();
    if (sub instanceof IRI) keys.add(buildPublicKey((IRI) sub));
  }
  // Also check for physical locations
  for (Iterator<Triple> it = graph.filter(null, RETRIEVED_FROM_URIREF, iri); it.hasNext();) {
    RDFTerm sub = it.next().getSubject();
    if (sub instanceof IRI) keys.add(buildPublicKey((IRI) sub));
  }
  return keys;
}

相关文章