本文整理了Java中xdi2.core.Graph
类的一些代码示例,展示了Graph
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph
类的具体详情如下:
包路径:xdi2.core.Graph
类名称:Graph
[英]This interface represents a whole XDI graph. XDI graphs consist of context nodes, relations, and literals. Also, an XDI graph can be expressed as a set of XDI statements.
[中]此接口表示整个XDI图。XDI图由上下文节点、关系和文字组成。此外,XDI图可以表示为一组XDI语句。
代码示例来源: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
/**
* Factory method that finds or creates an XDI relationship link contract for a graph.
* @return The XDI relationship link contract.
*/
public static RelationshipLinkContract findRelationshipLinkContract(Graph graph, XDIAddress authorizingAuthority, XDIAddress requestingAuthority, XDIAddress templateAuthorityAndId, XDIArc instanceXDIArc, boolean create) {
XDIAddress relationshipLinkContractXDIAddress = createRelationshipLinkContractXDIAddress(authorizingAuthority, requestingAuthority, templateAuthorityAndId, instanceXDIArc);
ContextNode relationshipLinkContractContextNode = create ? graph.setDeepContextNode(relationshipLinkContractXDIAddress) : graph.getDeepContextNode(relationshipLinkContractXDIAddress, true);
if (relationshipLinkContractContextNode == null) return null;
return new RelationshipLinkContract(XdiAbstractEntity.fromContextNode(relationshipLinkContractContextNode));
}
代码示例来源:origin: projectdanube/xdi2
private synchronized void read(Graph graph, String string) throws Xdi2ParseException {
for (XDIReader xdiReader : readers) {
if (xdiReader instanceof AutoReader) continue;
try {
graph.clear();
xdiReader.read(graph, new StringReader(string));
this.lastSuccessfulReader = xdiReader;
return;
} catch(Exception ex) {
continue;
}
}
this.lastSuccessfulReader = null;
throw new Xdi2ParseException("Unknown serialization format.");
}
代码示例来源:origin: projectdanube/xdi2
/**
* Factory method that finds or creates an XDI link contract template for a graph.
* @return The XDI link contract template.
*/
public static LinkContractTemplate findLinkContractTemplate(Graph graph, XDIAddress templateAuthorityAndId, boolean create) {
XDIAddress linkContractTemplateXDIAddress = createLinkContractTemplateXDIAddress(templateAuthorityAndId);
ContextNode linkContractTemplateContextNode = create ? (ContextNode) graph.setDeepNode(linkContractTemplateXDIAddress) : (ContextNode) graph.getDeepNode(linkContractTemplateXDIAddress, true);
if (linkContractTemplateContextNode == null) return null;
return new LinkContractTemplate(XdiEntitySingleton.Variable.fromContextNode(linkContractTemplateContextNode));
}
代码示例来源:origin: projectdanube/xdi2
/**
* Copies a context node into a target graph.
* @param contextNode A context node from any graph.
* @param targetGraph The target graph.
* @param copyStrategy The strategy to determine what to copy.
* @return The copied context node in the target graph.
*/
public static ContextNode copyContextNode(ContextNode contextNode, Graph targetGraph, CopyStrategy copyStrategy) {
if (contextNode == null) throw new NullPointerException();
if (targetGraph == null) throw new NullPointerException();
if (copyStrategy == null) copyStrategy = DEFAULT_COPY_STRATEGY;
ContextNode targetContextNode;
XDIAddress contextNodeXDIAddress = contextNode.getXDIAddress();
if (contextNode.isRootContextNode()) {
targetContextNode = targetGraph.getRootContextNode(false);
copyContextNodeContents(contextNode, targetContextNode, copyStrategy);
} else {
targetContextNode = targetGraph.setDeepContextNode(contextNodeXDIAddress);
copyContextNodeContents(contextNode, targetContextNode, copyStrategy);
}
return targetContextNode;
}
代码示例来源:origin: projectdanube/xdi2
graph18.setStatement(XDIStatement.create("=markus<#email>/&/\"Markus Sabadello\""));
graph18.setStatement(XDIStatement.create("=markus/#friend/=neustar=les"));
ContextNode markus = graph18.getDeepContextNode(XDIAddress.create("=markus"));
ContextNode attribute = markus.getDeepContextNode(XDIAddress.create("<#email>"));
graph18.beginTransaction();
assertTrue(markus.containsRelation(XDIAddress.create("$is#"), XDIAddress.create("#person")));
graph18.rollbackTransaction();
if (graph18.supportsTransactions()) {
graph18.beginTransaction();
graph18.clear();
graph18.rollbackTransaction();
assertTrue(graph18.supportsTransactions() ? ! graph18.isEmpty() : graph18.isEmpty());
graph18.beginTransaction();
graph18.clear();
graph18.commitTransaction();
assertTrue(graph18.isEmpty());
graph18.close();
代码示例来源:origin: projectdanube/xdi2
List<Relation> refRepRelations = new IteratorListMaker<Relation> (Equivalence.getAllReferenceAndReplacementRelations(operationResultGraph.getRootContextNode(true))).list();
ContextNode refRepTargetContextNode = operationResultGraph.getDeepContextNode(targetXDIAddress, true);
if (refRepTargetContextNode != null && ! operationResultGraph.isEmpty()) {
ContextNode tempContextNode = tempGraph.setDeepContextNode(refRepContextNode.getXDIAddress());
CopyUtil.copyContextNodeContents(refRepTargetContextNode, tempContextNode, null);
tempGraph.close();
} else {
if (operationResultGraph.containsStatement(refRepRelation.getStatement().getXDIStatement())) {
代码示例来源:origin: projectdanube/xdi2
ContextNode innerRootContextNode = graph30.getRootContextNode().setContextNode(XDIArc.create("(=a=b=c/+d)"));
assertNotNull(graph30.getRootContextNode().getDeepContextNode(XDIAddress.create("(=a=b=c/+d)")));
assertNotNull(graph30.getRootContextNode().getDeepContextNode(XDIAddress.create("=a=b=c")));
assertNotNull(graph30.getRootContextNode().getDeepContextNode(XDIAddress.create("=a=b=c")).getRelation(XDIAddress.create("+d")));
assertEquals(graph30.getRootContextNode().getDeepContextNode(XDIAddress.create("=a=b=c")).getRelation(XDIAddress.create("+d")).follow(), innerRootContextNode);
assertEquals(graph30.getRootContextNode().getAllContextNodeCount(), 4);
assertEquals(graph30.getRootContextNode().getAllRelationCount(), 1);
assertEquals(graph30.getRootContextNode().getAllStatementCount(), 5);
graph30.getRootContextNode().getContextNode(XDIArc.create("=a")).delContextNode(XDIArc.create("=b"));
assertNull(graph30.getRootContextNode().getDeepContextNode(XDIAddress.create("(=a=b=c/+d)")));
assertNull(graph30.getRootContextNode().getDeepContextNode(XDIAddress.create("=a=b=c")));
assertEquals(graph30.getRootContextNode().getAllContextNodeCount(), 1);
assertEquals(graph30.getRootContextNode().getAllRelationCount(), 0);
assertEquals(graph30.getRootContextNode().getAllStatementCount(), 1);
graph30.getRootContextNode().setContextNode(XDIArc.create("(=a=b=c/+d)"));
graph30.clear();
assertNull(graph30.getRootContextNode().getDeepContextNode(XDIAddress.create("(=a=b=c/+d)")));
assertNull(graph30.getRootContextNode().getDeepContextNode(XDIAddress.create("=a=b=c")));
assertEquals(graph30.getRootContextNode().getAllContextNodeCount(), 0);
assertEquals(graph30.getRootContextNode().getAllRelationCount(), 0);
assertEquals(graph30.getRootContextNode().getAllStatementCount(), 0);
assertNotNull(graph30.getRootContextNode().getDeepContextNode(XDIAddress.create("(=a=b=c/+d)")));
代码示例来源:origin: projectdanube/xdi2
public void testReadJson() throws Exception {
Graph graph3 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-3");
XDIReader reader = XDIReaderRegistry.forFormat("XDI/JSON", null);
reader.read(graph3, AbstractGraphTest.class.getResourceAsStream("test.json")).close();
testGraph(graph3);
graph3.getRootContextNode().clear();
assertTrue(graph3.isEmpty());
graph3.close();
}
代码示例来源: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
public void testDelRelationDelInnerRoot() throws Exception {
Graph graph33 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-33");
graph33.getRootContextNode().setContextNode(XDIArc.create("(=a/#b)"));
assertEquals(graph33.getAllStatementCount(), 3);
graph33.getRootContextNode().getContextNode(XDIArc.create("=a")).delRelations(XDIAddress.create("#b"));
assertEquals(graph33.getAllStatementCount(), 1);
assertFalse(graph33.containsStatement(XDIStatement.create("//(=a/#b)")));
assertTrue(graph33.containsStatement(XDIStatement.create("//=a")));
assertFalse(graph33.containsStatement(XDIStatement.create("=a/#b/(=a/#b)")));
graph33.clear();
graph33.getRootContextNode().setContextNode(XDIArc.create("(/#b)"));
assertEquals(graph33.getAllStatementCount(), 2);
graph33.getRootContextNode().delRelations(XDIAddress.create("#b"));
assertEquals(graph33.getAllStatementCount(), 0);
assertFalse(graph33.containsStatement(XDIStatement.create("//(/#b)")));
assertFalse(graph33.containsStatement(XDIStatement.create("/#b/(/#b)")));
graph33.clear();
graph33.close();
}
代码示例来源:origin: projectdanube/xdi2
public void testLinkContracts() throws Exception {
Graph graph = MemoryGraphFactory.getInstance().openGraph();
ContextNode contextNode1 = graph.setDeepContextNode(XDIAddress.create("(=alice/$public)$contract"));
ContextNode contextNode2 = graph.setDeepContextNode(XDIAddress.create("(=alice/=alice)$contract"));
assertTrue(LinkContract.isValid(XdiAbstractEntity.fromContextNode(contextNode1)));
assertTrue(LinkContract.isValid(XdiAbstractEntity.fromContextNode(contextNode2)));
LinkContract linkContract1 = LinkContract.fromXdiEntity(XdiAbstractEntity.fromContextNode(contextNode1));
LinkContract linkContract2 = LinkContract.fromXdiEntity(XdiAbstractEntity.fromContextNode(contextNode2));
assertTrue(new IteratorContains<LinkContract> (LinkContracts.getAllLinkContracts(graph), linkContract1).contains());
assertTrue(new IteratorContains<LinkContract> (LinkContracts.getAllLinkContracts(graph), linkContract2).contains());
graph.close();
}
代码示例来源:origin: projectdanube/xdi2
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\""));
assertNotNull(graph22.getDeepContextNode(XDIAddress.create("=markus")));
assertNotNull(graph22.getDeepContextNode(XDIAddress.create("=neustar")));
assertNotNull(graph22.getDeepContextNode(XDIAddress.create("=neustar=les")));
assertNotNull(graph22.getDeepContextNode(XDIAddress.create("=markus")).getRelation(XDIAddress.create("#friend")));
assertNotNull(graph22.getDeepContextNode(XDIAddress.create("=markus")).getRelation(XDIAddress.create("#friend"), XDIAddress.create("=neustar=les")));
assertNotNull(graph22.getDeepContextNode(XDIAddress.create("=markus<#email>")).getLiteralNode());
assertNotNull(graph22.getDeepContextNode(XDIAddress.create("=markus<#email>")).getLiteralNode("markus@projectdanube.org"));
assertTrue(graph22.containsStatement(XDIStatement.create("=neustar//=les")));
assertTrue(graph22.containsStatement(XDIStatement.create("=markus/#friend/=neustar=les")));
assertTrue(graph22.containsStatement(XDIStatement.create("=markus<#email>/&/\"markus@projectdanube.org\"")));
assertEquals(graph22.getStatement(XDIStatement.create("=neustar//=les")).getXDIStatement(), XDIStatement.create("=neustar//=les"));
assertEquals(graph22.getStatement(XDIStatement.create("=markus/#friend/=neustar=les")).getXDIStatement(), "=markus/#friend/=neustar=les");
assertEquals(graph22.getStatement(XDIStatement.create("=markus<#email>/&/\"markus@projectdanube.org\"")).getXDIStatement(), "=markus<#email>/&/\"markus@projectdanube.org\"");
assertTrue(graph22.getStatement(XDIStatement.create("=neustar//=les")) instanceof ContextNodeStatement);
assertTrue(graph22.getStatement(XDIStatement.create("=markus/#friend/=neustar=les")) instanceof RelationStatement);
assertTrue(graph22.getStatement(XDIStatement.create("=markus<#email>/&/\"markus@projectdanube.org\"")) instanceof LiteralStatement);
assertTrue(graph22.getStatement(XDIStatement.create("=neustar//=les")).getXDIStatement().isContextNodeStatement());
assertTrue(graph22.getStatement(XDIStatement.create("=markus/#friend/=neustar=les")).getXDIStatement().isRelationStatement());
assertTrue(graph22.getStatement(XDIStatement.create("=markus<#email>/&/\"markus@projectdanube.org\"")).getXDIStatement().isLiteralStatement());
assertNotNull(graph23.getDeepContextNode(XDIAddress.create("=markus")));
assertNotNull(graph23.getDeepContextNode(XDIAddress.create("=neustar")));
assertNotNull(graph23.getDeepContextNode(XDIAddress.create("=neustar=les")));
代码示例来源:origin: projectdanube/xdi2
/**
* Given a graph, finds and returns the XDI common root.
* @param graph The graph.
* @return The XDI common root.
*/
public static XdiCommonRoot findCommonRoot(Graph graph) {
ContextNode commonRootContextNode = graph.getRootContextNode(false);
return new XdiCommonRoot(commonRootContextNode);
}
代码示例来源:origin: projectdanube/xdi2
@Override
public void executeDelOnAddress(XDIAddress targetXDIAddress, DelOperation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException {
if (XDIConstants.XDI_ADD_ROOT.equals(targetXDIAddress)) {
this.getGraph().clear();
} else if (targetXDIAddress.getNumXDIArcs() == 1) {
this.getGraph().getRootContextNode(false).delContextNode(targetXDIAddress.getFirstXDIArc());
} else {
XDIAddress parentContextNodeXDIAddress = XDIAddressUtil.parentXDIAddress(targetXDIAddress, -1);
XDIArc XDIarc = targetXDIAddress.getLastXDIArc();
ContextNode parentContextNode = this.getGraph().getDeepContextNode(parentContextNodeXDIAddress, false);
if (parentContextNode == null) return;
if (XDIConstants.XDI_ARC_LITERAL.equals(XDIarc)) {
parentContextNode.delLiteralNode();
} else {
parentContextNode.delContextNode(XDIarc);
}
}
}
代码示例来源:origin: projectdanube/xdi2
@Override
public ContextNode getContextNode(XDIAddress nodeXDIAddress) {
Graph resolvedGraph = this.resolveGraph(nodeXDIAddress);
XDIAddress resolvedcontextNodeXDIAddress = this.resolveXDIAddress(nodeXDIAddress);
ContextNode resolvedContextNode = resolvedGraph.getDeepContextNode(resolvedcontextNodeXDIAddress, false);
if (log.isTraceEnabled()) log.trace("getContextNode(" + nodeXDIAddress + ") --> " + resolvedcontextNodeXDIAddress + " --> " + resolvedContextNode);
return resolvedContextNode;
}
代码示例来源:origin: projectdanube/xdi2
assertEquals(graph10.compareTo(graph11), 0);
assertEquals(graph11.compareTo(graph10), 0);
XDIWriterRegistry.forFormat("XDI/JSON", null).write(graph10, buffer1);
XDIWriterRegistry.forFormat("XDI DISPLAY", null).write(graph11, buffer2);
graph10.clear();
graph11.clear();
XDIReaderRegistry.forFormat("XDI/JSON", null).read(graph10, new StringReader(buffer1.toString()));
XDIReaderRegistry.forFormat("XDI DISPLAY", null).read(graph11, new StringReader(buffer2.toString()));
assertEquals(graph10.compareTo(graph11), 0);
assertEquals(graph11.compareTo(graph10), 0);
graph11.getRootContextNode().setContextNode(XDIArc.create("=xxx"));
assertNotEquals(graph10.compareTo(graph11), 0);
} finally {
graph10.close();
graph11.close();
代码示例来源:origin: projectdanube/xdi2
@Override
public void shutdown() throws Exception {
super.shutdown();
this.graph.close();
}
代码示例来源:origin: projectdanube/xdi2
public void testTimestampsOnContextNode() throws Exception {
Graph graph = MemoryGraphFactory.getInstance().openGraph();
ContextNode contextNode = graph.getRootContextNode().setContextNode(XDIArc.create("=markus"));
GregorianCalendar calendar = new GregorianCalendar(2010, 11, 22, 11, 22, 33);
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
Date timestamp = calendar.getTime();
Timestamps.setTimestamp(XdiAbstractContext.fromContextNode(contextNode), timestamp);
assertEquals(timestamp, Timestamps.getTimestamp(XdiAbstractContext.fromContextNode(contextNode)));
graph.close();
}
}
代码示例来源:origin: projectdanube/xdi2
@Test
public void testDuplicateDatatypes() throws Exception {
StringBuilder buffer = new StringBuilder();
buffer.append("=markus<#age>/&/\"33\"\n");
buffer.append("=markus<#age>/$is#/+$xsd$int\n");
buffer.append("=markus<#age>/$is#/+$json$number\n");
String xdiString = buffer.toString();
try {
Graph graph = (new MemoryGraphFactory()).parseGraph(xdiString);
DataTypes.setDataType(graph.getDeepContextNode(XDIAddress.create("=markus<#age>")), XDIAddress.create("+$json$number"));
fail();
graph.close();
} catch (Exception ex) { }
}
}
内容来源于网络,如有侵权,请联系作者删除!