xdi2.core.Graph.setStatement()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(14.1k)|赞(0)|评价(0)|浏览(178)

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

Graph.setStatement介绍

[英]Sets a statement in this graph.
[中]在此图中设置一条语句。

代码示例

代码示例来源:origin: projectdanube/xdi2

@Override
public void executeSetOnStatement(XDIStatement targetStatement, SetOperation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException {
  this.getGraph().setStatement(targetStatement);
}

代码示例来源:origin: projectdanube/xdi2

/**
 * Copies a statement into another graph.
 * @param statement A statement from any graph.
 * @param targetGraph The target graph.
 * @param copyStrategy The strategy to determine what to copy.
 * @return The copied statement in the target graph.
 */
public static Statement copyStatement(Statement statement, Graph targetGraph, CopyStrategy copyStrategy) {
  if (statement == null) throw new NullPointerException();
  if (targetGraph == null) throw new NullPointerException();
  if (copyStrategy == null) copyStrategy = DEFAULT_COPY_STRATEGY;
  targetGraph.setStatement(statement.getXDIStatement());
  return null;
}

代码示例来源:origin: projectdanube/xdi2

private static void read(Graph graph, BufferedReader bufferedReader) throws IOException, Xdi2ParseException {
  String line;
  int lineNr = 0;
  while ((line = bufferedReader.readLine()) != null) {
    lineNr++;
    line = line.trim();
    if (line.isEmpty()) continue;
    XDIStatement XDIstatement;
    try {
      XDIstatement = XDIStatement.create(line);
    } catch (Exception ex) {
      throw new Xdi2ParseException("Parser problem at line " + lineNr + ": " + ex.getMessage(), ex);
    }
    // add the statement to the graph
    try {
      graph.setStatement(XDIstatement);
    } catch (Exception ex) {
      throw new Xdi2ParseException("Graph problem at line " + lineNr + ": " + ex.getMessage(), ex);
    }
  }
}

代码示例来源:origin: projectdanube/xdi2

@Override
public InterceptorResult after(Operation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException {
  // add $is statements for all the substituted variables
  for (Entry<XDIArc, XDIArc> entry : getVariablesPerOperation(executionContext).entrySet()) {
    XDIAddress subject = XDIAddress.create(entry.getKey().toString());
    XDIAddress predicate = XDIDictionaryConstants.XDI_ADD_IS;
    XDIAddress object = XDIAddress.create(entry.getValue().toString());
    XDIStatement statement = XDIStatement.fromComponents(subject, predicate, object);
    operationResultGraph.setStatement(statement);
  }
  // done
  
  return InterceptorResult.DEFAULT;
}

代码示例来源:origin: projectdanube/xdi2

@Override
  public ContributorResult executeGetOnAddress(
      XDIAddress[] contributorAddresses,
      XDIAddress contributorsAddress,
      XDIAddress relativeTargetAddress,
      GetOperation operation,
      Graph operationResultGraph,
      ExecutionContext executionContext) throws Xdi2MessagingException {

    operationResultGraph.setStatement(XDIStatement.fromLiteralComponents(
        XDIAddress.create("" + contributorsAddress),
        this.value));

    return ContributorResult.DEFAULT;
  }
}

代码示例来源:origin: projectdanube/xdi2

@Override
  public ContributorResult executeGetOnAddress(
      XDIAddress[] contributorAddresses,
      XDIAddress contributorsAddress,
      XDIAddress relativeTargetAddress,
      GetOperation operation,
      Graph operationResultGraph,
      ExecutionContext executionContext) throws Xdi2MessagingException {

    operationResultGraph.setStatement(XDIStatement.fromLiteralComponents(
        XDIAddress.create("" + contributorsAddress + "=a<#b>"),
        this.value));

    operationResultGraph.setStatement(XDIStatement.fromRelationComponents(
        XDIAddress.create("" + contributorsAddress + "=x*y"),
        XDIAddress.create("" + "#c"),
        XDIAddress.create("" + contributorsAddress + "=d*e")));

    return ContributorResult.DEFAULT;
  }
}

代码示例来源:origin: projectdanube/xdi2

public void testNormalizedSerialization() throws Exception {

    Graph graph = MemoryGraphFactory.getInstance().openGraph();
    graph.setStatement(XDIStatement.create("=markus<#email>/&/\"markus@projectdanube.org\""));
    graph.setStatement(XDIStatement.create("=markus/#friend/=animesh"));

    ContextNode contextNode = graph.getDeepContextNode(XDIAddress.create("=markus"));

    String normalizedSerialization = "{\"/\":[\"=animesh\",\"=markus\"],\"=markus/\":[\"<#email>\"],\"=markus/#friend\":[\"=animesh\"],\"=markus<#email>/&\":\"markus@projectdanube.org\"}";

    assertEquals(Normalization.serialize(contextNode, null), normalizedSerialization);

    graph.close();
  }
}

代码示例来源:origin: projectdanube/xdi2

@Override
  public ContributorResult executeGetOnAddress(
      XDIAddress[] contributorAddresses,
      XDIAddress contributorsAddress,
      XDIAddress relativeTargetAddress,
      GetOperation operation,
      Graph operationResultGraph,
      ExecutionContext executionContext) throws Xdi2MessagingException {

    operationResultGraph.setStatement(XDIStatement.fromRelationComponents(
        XDIAddress.create("" + contributorsAddress + "=markus"),
        XDIAddress.create("" + "#friend"),
        XDIAddress.create("" + contributorsAddress + "=animesh")));

    return ContributorResult.DEFAULT;
  }
}

代码示例来源:origin: projectdanube/xdi2

public void testCopyUtil() throws Exception {
  Graph graph = MemoryGraphFactory.getInstance().openGraph();
  graph.setStatement(XDIStatement.create("=markus<#email>/&/\"markus@projectdanube.org\""));
  graph.setStatement(XDIStatement.create("=markus/#friend/=neustar=animesh"));
  graph.setStatement(XDIStatement.create("=neustar=animesh<#email>/&/\"animesh@gmail.com\""));
  graph.setStatement(XDIStatement.create("=neustar=animesh/#friend/=markus"));
  Graph graph2 = MemoryGraphFactory.getInstance().openGraph();
  CopyUtil.copyGraph(graph, graph2, null);
  Graph graph3 = MemoryGraphFactory.getInstance().openGraph();
  CopyUtil.copyGraph(graph, graph3, null);
  CopyUtil.copyGraph(graph2, graph3, null);
  assertEquals(graph, graph2);
  assertEquals(graph2, graph3);
  assertEquals(graph3, graph);
  graph.close();
  graph2.close();
  graph3.close();
}

代码示例来源:origin: projectdanube/xdi2

public void testNoExceptions() throws Exception {
  Graph graph17 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-17");
  graph17.setStatement(XDIStatement.create("=markus<#email>/&/\"Markus Sabadello\""));
  graph17.setStatement(XDIStatement.create("=markus/#friend/=neustar=les"));
  ContextNode root = graph17.getRootContextNode();
  ContextNode markus = graph17.getDeepContextNode(XDIAddress.create("=markus"));
  ContextNode les = graph17.getDeepContextNode(XDIAddress.create("=neustar=les"));
  root.setContextNode(XDIArc.create("=markus"));
  markus.setDeepContextNode(XDIAddress.create("<#email>")).setLiteralNode("test");
  markus.setRelation(XDIAddress.create("#friend"), les);
  graph17.close();
}

代码示例来源:origin: projectdanube/xdi2

public void testDeleteCyclicRelation() throws Exception {
  Graph graph31 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-31");
  graph31.setStatement(XDIStatement.create("=a=b=c=d=e/+x/=a=b=c"));
  graph31.setStatement(XDIStatement.create("=m=n=o/+y/=a=b=c=d"));
  graph31.getDeepContextNode(XDIAddress.create("=a=b")).delete();
  assertEquals(graph31.getRootContextNode().getAllContextNodeCount(), 4);
  assertEquals(graph31.getRootContextNode().getAllRelationCount(), 0);
  assertEquals(graph31.getRootContextNode().getAllStatementCount(), 4);
  graph31.close();
}

代码示例来源:origin: projectdanube/xdi2

public void testMultipleReplacements() throws Exception {
  Graph graph1 = MemoryGraphFactory.getInstance().openGraph();
  Graph graph2 = MemoryGraphFactory.getInstance().openGraph();
  graph1.setStatement(XDIStatement.create("=a=b=c/+e/=f"));
  XDIArc from1 = XDIArc.create("=b");
  List<XDIAddress> to1 = new ArrayList<XDIAddress> ();
  to1.add(XDIAddress.create("=x"));
  to1.add(XDIAddress.create("=y"));
  XDIArc from2 = XDIArc.create("=f");
  List<XDIAddress> to2 = new ArrayList<XDIAddress> ();
  to2.add(XDIAddress.create("=m"));
  to2.add(XDIAddress.create("=n"));
  Map<XDIArc, Object> replacements = new HashMap<XDIArc, Object> ();
  replacements.put(from1, to1);
  replacements.put(from2, to2);
  CopyUtil.copyGraph(graph1, graph2, new ReplaceXDIAddressCopyStrategy(replacements));
  assertTrue(graph2.containsStatement(XDIStatement.create("=a=x=c/+e/=m")));
  assertTrue(graph2.containsStatement(XDIStatement.create("=a=x=c/+e/=n")));
  assertTrue(graph2.containsStatement(XDIStatement.create("=a=y=c/+e/=m")));
  assertTrue(graph2.containsStatement(XDIStatement.create("=a=y=c/+e/=n")));
  assertEquals(graph2.getAllStatementCount(), 11);
  graph1.close();
  graph2.close();
}

代码示例来源:origin: projectdanube/xdi2

public void testSignAndValidateKeyPair() throws Exception {
  KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA");
  keyPairGen.initialize(1024);
  KeyPair keyPair = keyPairGen.generateKeyPair();
  RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
  RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
  Graph graph = MemoryGraphFactory.getInstance().openGraph();
  graph.setStatement(XDIStatement.create("=markus<#email>/&/\"markus@projectdanube.org\""));
  graph.setStatement(XDIStatement.create("=markus/#friend/=animesh"));
  ContextNode contextNode = graph.getDeepContextNode(XDIAddress.create("=markus"));
  RSASignature signature = new RSAStaticPrivateKeySignatureCreator(privateKey).createSignature(contextNode);
  signature = (RSASignature) Signatures.getSignatures(contextNode).next();
  assertEquals(signature.getDigestAlgorithm(), RSASignature.DIGEST_ALGORITHM_SHA);
  assertEquals(signature.getDigestVersion(), Integer.valueOf(256));
  assertEquals(signature.getKeyAlgorithm(), RSASignature.KEY_ALGORITHM_RSA);
  assertEquals(signature.getKeyLength(), Integer.valueOf(1024));
  assertEquals(signature.getJCEAlgorithm(), "SHA256withRSA");
  assertEquals(signature.getBaseContextNode(), contextNode);
  assertTrue(new RSAStaticPublicKeySignatureValidator(publicKey).validateSignature(signature));
  contextNode.setRelation(XDIAddress.create("#friend"), XDIAddress.create("=joseph"));
  assertFalse(new RSAStaticPublicKeySignatureValidator(publicKey).validateSignature(signature));
  graph.close();
}

代码示例来源:origin: projectdanube/xdi2

graph.setStatement(XDIStatement.create("=markus<#email>/&/\"markus@projectdanube.org\""));
graph.setStatement(XDIStatement.create("=markus/#friend/=animesh"));

代码示例来源:origin: projectdanube/xdi2

graph18.setStatement(XDIStatement.create("=markus<#email>/&/\"Markus Sabadello\""));
graph18.setStatement(XDIStatement.create("=markus/#friend/=neustar=les"));

代码示例来源:origin: projectdanube/xdi2

public void testDeleteContextNodesDeletesRelations() throws Exception {
  Graph graph27 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-27");
  Relation r1 = graph27.setDeepContextNode(XDIAddress.create("=animesh")).setRelation(XDIAddress.create("#friend"), XDIAddress.create("=markus"));
  Relation r2 = graph27.setDeepContextNode(XDIAddress.create("=markus")).setRelation(XDIAddress.create("#friend"), XDIAddress.create("=animesh"));
  ContextNode markus = (ContextNode) r1.follow();
  ContextNode animesh = (ContextNode) r2.follow();
  markus.delete();
  assertNotNull(graph27.getDeepContextNode(XDIAddress.create("=animesh")));
  assertFalse(graph27.getDeepContextNode(XDIAddress.create("=animesh")).getRelations().hasNext());
  assertFalse(graph27.getDeepContextNode(XDIAddress.create("=animesh")).getRelations(XDIAddress.create("#friend")).hasNext());
  assertEquals(graph27.getDeepContextNode(XDIAddress.create("=animesh")).getRelationCount(), 0);
  assertFalse(graph27.getDeepContextNode(XDIAddress.create("=animesh")).getIncomingRelations().hasNext());
  assertFalse(graph27.getDeepContextNode(XDIAddress.create("=animesh")).getIncomingRelations(XDIAddress.create("#friend")).hasNext());
  assertFalse(animesh.getRelations().hasNext());
  assertFalse(animesh.getRelations(XDIAddress.create("#friend")).hasNext());
  assertEquals(animesh.getRelationCount(), 0);
  assertFalse(animesh.getIncomingRelations().hasNext());
  assertFalse(animesh.getIncomingRelations(XDIAddress.create("#friend")).hasNext());
  animesh.delete();
  graph27.setStatement(XDIStatement.create("+a+b/$i/=x"));
  graph27.setStatement(XDIStatement.create("=x/$i/=y"));
  graph27.getRootContextNode().getContextNode(XDIArc.create("+a")).delete();
  assertEquals(graph27.getRootContextNode().getAllRelationCount(), 1);
  assertTrue(graph27.getRootContextNode().getContextNode(XDIArc.create("=x")).getRelations().hasNext());
  assertFalse(graph27.getRootContextNode().getContextNode(XDIArc.create("=x")).getIncomingRelations().hasNext());
  graph27.getRootContextNode().getContextNode(XDIArc.create("=x")).delete();
  assertEquals(graph27.getRootContextNode().getAllRelationCount(), 0);
  graph27.close();
}

代码示例来源:origin: projectdanube/xdi2

graph.setStatement(XDIStatement.create(invalidStatement));

代码示例来源:origin: projectdanube/xdi2

Graph graph23 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-23");
ContextNodeStatement statement22_1 = (ContextNodeStatement) graph22.setStatement(XDIStatement.create("=neustar//=les"));
RelationStatement statement22_2 = (RelationStatement) graph22.setStatement(XDIStatement.create("=markus/#friend/=neustar=les"));
LiteralStatement statement22_3 = (LiteralStatement) graph22.setStatement(XDIStatement.create("=markus<#email>/&/\"markus@projectdanube.org\""));

代码示例来源:origin: projectdanube/xdi2

graph16.setStatement(XDIStatement.create("=markus/#friend/=animesh"));
graph16.setStatement(XDIStatement.create("=markus/#friend/=neustar=les"));
graph16.setStatement(XDIStatement.create("=!:uuid:1111=!:uuid:2222/$is/=markus"));

代码示例来源:origin: projectdanube/xdi2

graph30.setStatement(XDIStatement.create("(=a/+b)(=x/+y)(=mm/+nn)=oo/+pp/=qq"));

相关文章