本文整理汇总了Java中org.hypergraphdb.HGPlainLink类的典型用法代码示例。如果您正苦于以下问题:Java HGPlainLink类的具体用法?Java HGPlainLink怎么用?Java HGPlainLink使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HGPlainLink类属于org.hypergraphdb包,在下文中一共展示了HGPlainLink类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testISChange
import org.hypergraphdb.HGPlainLink; //导入依赖的package包/类
@Test
public void testISChange()
{
final HyperGraph graph = getGraph();
graph.getTransactionManager().transact(new Callable<Object>() {
public Object call()
{
final HGHandle myatom = graph.add("testISChange");
// That'll bring the incidence set into the cache
Assert.assertTrue(graph.getIncidenceSet(myatom).isEmpty());
graph.getTransactionManager().transact(new Callable<Object>(){
public Object call()
{
// modify a structure in the cache within a nested transaction
graph.add(new HGPlainLink(myatom));
return null;
}
});
return null;
}
});
HGHandle x = hg.findOne(graph, hg.eq("testISChange"));
Assert.assertNotNull(x);
// the incidence set, still in the cache, should be updated
Assert.assertEquals(graph.getIncidenceSet(x).size(), 1);
}
示例2: testDepthFirstOnCircle
import org.hypergraphdb.HGPlainLink; //导入依赖的package包/类
@Test
public void testDepthFirstOnCircle()
{
HGHandle A = graph.add("A");
HGHandle B = graph.add("B");
HGHandle C = graph.add("C");
HGHandle D = graph.add("D");
HGHandle E = graph.add("E");
graph.add(new HGPlainLink(A, B));
graph.add(new HGPlainLink(B, C));
graph.add(new HGPlainLink(C, D));
graph.add(new HGPlainLink(D, E));
graph.add(new HGPlainLink(E, A));
for (Object x : graph.getAll(hg.dfs(A)))
System.out.println(x);
List<HGHandle> sequence = graph.findAll(hg.dfs(A));
sequence.add(0, A);
Assert.assertArrayEquals(new HGHandle[] {A, B, C, D, E}, sequence.toArray(new HGHandle[0]));
}
示例3: testCount
import org.hypergraphdb.HGPlainLink; //导入依赖的package包/类
@Test
public void testCount()
{
HGHandle n1 = graph.add(100);
HGHandle n2 = graph.add(1000l);
HGHandle n3 = graph.add(2000l);
HGHandle n4 = graph.add(10.10);
Assert.assertTrue(graph.findAll(hg.type(Integer.class)).contains(n1));
Assert.assertTrue(graph.findAll(hg.type(Long.class)).contains(n2));
graph.add(new SampleLink1(n1, n2));
graph.add(new SampleLink1(n1, n3));
graph.add(new HGPlainLink(n1, n4));
Assert.assertEquals(2, graph.count(hg.and(hg.incident(n1), hg.type(SampleLink1.class))));
// HGQuery siblings = hg.apply(, c) hg.incident(n1))
// Assert.assertEquals(1,
// hg.count(new PipeQuery<HGHandle, HGHandle>(
// hg.and(hg.not(hg.is(n1)),
// hg.apply(hg.deref(graph),
// hg.target(linkHandle)
//
// hg.type(Double.class)))
// )
}
示例4: testPositionedLinkCondition
import org.hypergraphdb.HGPlainLink; //导入依赖的package包/类
@Test
public void testPositionedLinkCondition()
{
HGHandle [] A = new HGHandle[10];
for (int i = 0; i < A.length; i++)
A[i] = graph.add("sdsfd" + T.random(Integer.MAX_VALUE));
ArrayList<HGHandle> links = new ArrayList<HGHandle>();
for (int i = 0; i < 5; i++)
links.add(graph.add(new HGPlainLink(A)));
Assert.assertTrue(hg.findAll(graph, hg.incidentAt(A[0], 0)).containsAll(links));
Assert.assertTrue(hg.findAll(graph, hg.incidentAt(A[A.length-1], -1)).containsAll(links));
Assert.assertTrue(hg.findAll(graph, hg.incidentAt(A[5], 3, 7)).containsAll(links));
Assert.assertTrue(hg.findAll(graph, hg.incidentAt(A[3], -4, -1)).isEmpty());
}
示例5: testVariableReplacement
import org.hypergraphdb.HGPlainLink; //导入依赖的package包/类
@Test
public void testVariableReplacement()
{
HyperGraph graph = getGraph();
HGHandle h1 = graph.add("target1");
HGHandle h2 = graph.add("target2");
HGHandle l1 = graph.add(new HGPlainLink(h1));
HGHandle l2 = graph.add(new HGPlainLink(h2));
HGHandle l3 = graph.add(new HGPlainLink(h1, h2));
// Incident condition
HGQuery<HGHandle> q = hg.make(HGHandle.class, getGraph()).compile(
hg.incident(hg.var("target")));
Set<HGHandle> S = q.var("target", h1).findInSet();
Assert.assertTrue(S.contains(l1));
Assert.assertTrue(S.contains(l3));
S = q.var("target", h2).findInSet();
Assert.assertTrue(S.contains(l2));
Assert.assertTrue(S.contains(l3));
// Type condition
q = hg.make(HGHandle.class, graph).compile(hg.type(hg.var("type")));
Assert.assertTrue(q.var("type", String.class).findAll().size() > 0);
Assert.assertTrue(q.var("type",
graph.getTypeSystem().getTypeHandle(HGSubgraph.class))
.findAll().size() == 0);
// Equals
HGHandle nameHandle = graph.add("krokus");
HGQuery<HGHandle> findName = HGQuery.make(HGHandle.class, graph)
.compile(hg.and(hg.type(String.class), hg.eq(hg.var("name"))));
Assert.assertEquals(nameHandle, findName.var("name", "krokus")
.findOne());
graph.remove(h1);
graph.remove(h2);
graph.remove(l1);
graph.remove(l2);
graph.remove(l3);
}
示例6: testSimpleConnection
import org.hypergraphdb.HGPlainLink; //导入依赖的package包/类
@Test
public void testSimpleConnection()
{
HGHandle x1 = hg.assertAtom(graph, "atom1");
HGHandle x2 = hg.assertAtom(graph, "atom2");
HGHandle x3 = hg.assertAtom(graph, "atom3");
HGHandle l1 = hg.assertAtom(graph, new HGPlainLink(x1, x2));
HGHandle l2 = hg.assertAtom(graph, new HGPlainLink(x2, x3));
Assert.assertTrue(graph.findOne(hg.and(hg.bfs(x1), hg.is(x3))).equals(x3));
}
示例7: addEntry
import org.hypergraphdb.HGPlainLink; //导入依赖的package包/类
/**
*
* Adds an event to the log.
* @param value
* @param peerFilter
* @return
*/
public LogEntry addEntry(LogEntry entry, Iterator<Object> targets)
{
//ensure only one at a time is logged
synchronized(timestamp)
{
Timestamp entryTimestamp = timestamp.moveNext();
entry.setTimestamp(entryTimestamp);
HGHandle timestampHandle = logDb.add(entryTimestamp);
logDb.getStore().store(LATEST_VERSION_HANDLE, (logDb.getPersistentHandle(timestampHandle)).toByteArray());
HGHandle opHandle = logDb.add(entry.operation);
logDb.add(new HGPlainLink(timestampHandle, entry.getLogEntryHandle(), opHandle));
//get timestamp, save,
while (targets.hasNext())
{
Object target = targets.next();
HGPeerIdentity targetId = peerInterface.getThisPeer().getIdentity(target);
Peer peer = getPeer(targetId);
//make connection with peer
HGPlainLink link = new HGPlainLink(peerHandles.get(targetId), entry.getLogEntryHandle());
logDb.add(link);
entry.setLastTimestamp(targetId, peer.getTimestamp());
peer.setTimestamp(entryTimestamp);
logDb.replace(peerHandles.get(targetId), peer);
System.out.println(entry.getLastTimestamp(targetId));
}
}
return entry;
}
示例8: getLogEntries
import org.hypergraphdb.HGPlainLink; //导入依赖的package包/类
public ArrayList<LogEntry> getLogEntries(Timestamp startingFrom, HGAtomPredicate interest)
{
//find all timestamps greater then a value
ArrayList<LogEntry> result = new ArrayList<LogEntry>();
HGSearchResult<HGHandle> timestamps = logDb.find(hg.and(hg.type(Timestamp.class), hg.value(startingFrom, ComparisonOperator.LT)));
while(timestamps.hasNext())
{
HGHandle handle = timestamps.next();
for(HGHandle linkHandle : logDb.getIncidenceSet(handle))
{
HGPlainLink link = logDb.get(linkHandle);
if (link.getArity() > 1)
{
if (interest.satisfies(logDb, link.getTargetAt(1)))
{
Timestamp ts = logDb.get(handle);
LogEntry entry = new LogEntry(link.getTargetAt(1), logDb, ts);
entry.setOperation((StorageService.Operation)logDb.get(link.getTargetAt(2)));
result.add(entry);
}
}
}
}
// TODO Auto-generated method stub
return result;
}
示例9: testSubgraphOperations
import org.hypergraphdb.HGPlainLink; //导入依赖的package包/类
@Test
public void testSubgraphOperations()
{
HGSubgraph subgraph = new HGSubgraph();
graph.add(subgraph);
HGHandle stringType = graph.getTypeSystem().getTypeHandle(String.class);
HGHandle linkType = graph.getTypeSystem().getTypeHandle(HGPlainLink.class);
HGHandle globalAtom = graph.add("global");
subgraph.add(globalAtom);
Assert.assertTrue(subgraph.isMember(globalAtom));
HGHandle globalOnly = graph.add("globalOnly");
HGHandle localAtom = subgraph.add("localAtom", stringType, 0);
Assert.assertTrue(subgraph.isMember(localAtom));
HGHandle localDefine = graph.getHandleFactory().makeHandle();
subgraph.define(localDefine, stringType, "localDefinedAtom", 0);
Assert.assertTrue(subgraph.isMember(localDefine));
HGHandle toBeRemoved = subgraph.add("toBeRemoved", stringType, 0);
Assert.assertTrue(subgraph.isMember(toBeRemoved));
subgraph.remove(toBeRemoved);
HGHandle toBeReplaced = subgraph.add("toBeReplaced", stringType, 0);
Assert.assertTrue(subgraph.get(toBeReplaced).equals("toBeReplaced"));
// A b/w atoms in the subgraph, attached itself to the subgraph
HGHandle localLink1 = subgraph.add(new HGPlainLink(localAtom, globalAtom), linkType, 0);
// A b/w atoms not all in the subgraph, but still attached itself to the subgraph
HGHandle localLink2 = subgraph.add(new HGPlainLink(globalOnly, localAtom), linkType, 0);
// A b/w atoms in the subgraph, but not attached itself to the subgraph
HGHandle globalLink = graph.add(new HGPlainLink(localDefine, globalAtom), linkType, 0);
HGHandle globalLink2 = graph.add(new HGPlainLink(globalOnly, localDefine, globalAtom), linkType, 0);
Assert.assertFalse(subgraph.getIncidenceSet(localDefine).contains(globalLink2));
reopenDb();
stringType = graph.getTypeSystem().getTypeHandle(String.class);
subgraph = graph.get(subgraph.getAtomHandle().getPersistent());
Assert.assertNull(subgraph.get(globalOnly));
Assert.assertNull(subgraph.findOne(hg.eq("toBeRemoved")));
Assert.assertNotNull(graph.findOne(hg.eq("toBeRemoved")));
subgraph.replace(toBeReplaced, "alreadyReplaced", stringType);
Assert.assertEquals(graph.getOne(hg.eq("toBeReplaced")), null);
Assert.assertEquals(HGUtils.set(subgraph.getAll(hg.type(String.class)).toArray()),
HGUtils.set(new Object[] {"global", "localAtom", "localDefinedAtom", "alreadyReplaced" }));
// Checks links and incidence sets
Assert.assertTrue(subgraph.isMember(localLink1));
Assert.assertTrue(subgraph.isMember(localLink2));
Assert.assertFalse(subgraph.isMember(globalLink));
Assert.assertEquals(subgraph.getIncidenceSet(localAtom).size(), 2);
Assert.assertEquals(subgraph.getIncidenceSet(globalAtom).size(), 1);
Assert.assertEquals(subgraph.getIncidenceSet(localDefine).size(), 0);
Assert.assertEquals(subgraph.getIncidenceSet(globalOnly).size(), 1);
Assert.assertEquals(HGUtils.set(subgraph.getIncidenceSet(localAtom).toArray()),
HGUtils.set(new Object[] { localLink1, localLink2 }));
}
示例10: testCommonAdjacencyPattern
import org.hypergraphdb.HGPlainLink; //导入依赖的package包/类
@Test
public void testCommonAdjacencyPattern()
{
HGHandle a = graph.add("A");
HGHandle b = graph.add("B");
HGHandle c1 = graph.add("C1");
HGHandle c2 = graph.add("C2");
HGHandle c3 = graph.add("C3");
HGHandle c4 = graph.add("C4");
HGHandle c5 = graph.add("C5");
graph.add(new HGPlainLink(c1, a));
graph.add(new HGPlainLink(c1, b));
graph.add(new HGPlainLink(c1, c2));
graph.add(new HGPlainLink(c2, a));
graph.add(new HGPlainLink(c2, c3));
graph.add(new HGPlainLink(c4, a));
graph.add(new HGPlainLink(c4, b));
graph.add(new HGPlainLink(c5, b));
graph.add(new HGPlainLink(c5, b));
graph.add(new HGPlainLink(c5, c2));
HGQueryCondition cond = hg.and(
hg.type(String.class),
hg.and(
hg.apply(
hg.targetAt(graph, 0), // follow target[0] of the OrderedLink
hg.orderedLink(hg.anyHandle(), a) // links pointing to A
),
hg.apply(
hg.targetAt(graph, 0), // follow target[0] of the OrderedLink
hg.orderedLink(hg.anyHandle(), b) // links pointing to B
)
)
);
List<HGHandle> L = hg.findAll(graph, cond);
assertTrue(L.contains(c1));
assertFalse(L.contains(c2));
assertFalse(L.contains(c3));
assertTrue(L.contains(c4));
assertFalse(L.contains(c5));
}
示例11: populate
import org.hypergraphdb.HGPlainLink; //导入依赖的package包/类
public static void populate(HyperGraph graph, int nodes)
{
ArrayList<HGHandle> L2 = new ArrayList<HGHandle>();
ArrayList<HGHandle> L3 = new ArrayList<HGHandle>();
ArrayList<HGHandle> L4 = new ArrayList<HGHandle>();
ArrayList<HGHandle> L5 = new ArrayList<HGHandle>();
for (int i = 0; i < nodes; i++)
{
int x = i % 100;
SimpleBean node = new SimpleBean();
node.setIntProp(i);
HGHandle nodeHandle = graph.add(node);
if (x < 5)
{
graph.add(new HGPlainLink(nodeHandle));
}
else if (x < 10)
{
L5.add(nodeHandle);
if (L5.size() == 5)
{
graph.add(new HGPlainLink(L5.toArray(new HGHandle[0])));
L5.clear();
}
}
else if (x < 30)
{
L3.add(nodeHandle);
if (L3.size() == 3)
{
graph.add(new HGPlainLink(L3.toArray(new HGHandle[0])));
L3.clear();
}
}
else if (x < 50)
{
L4.add(nodeHandle);
if (L4.size() == 4)
{
graph.add(new HGPlainLink(L4.toArray(new HGHandle[0])));
L4.clear();
}
}
else
{
L2.add(nodeHandle);
if (L2.size() == 2)
{
graph.add(new HGPlainLink(L2.toArray(new HGHandle[0])));
L2.clear();
}
}
}
}
示例12: isPresent
import org.hypergraphdb.HGPlainLink; //导入依赖的package包/类
public boolean isPresent(HyperGraph graph)
{
return graph.getTypeSystem().getHandleForIdentifier(this.toTypeURI(HGPlainLink.class)) != null;
}
示例13: make
import org.hypergraphdb.HGPlainLink; //导入依赖的package包/类
public Object make(HGPersistentHandle handle, LazyRef<HGHandle[]> targetSet, IncidenceSetRef incidenceSet)
{
return new HGPlainLink(targetSet.deref());
}