本文整理汇总了Java中org.hypergraphdb.util.Mapping类的典型用法代码示例。如果您正苦于以下问题:Java Mapping类的具体用法?Java Mapping怎么用?Java Mapping使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Mapping类属于org.hypergraphdb.util包,在下文中一共展示了Mapping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeTransferedGraph
import org.hypergraphdb.util.Mapping; //导入依赖的package包/类
/**
* @param atom A Structs representation of a transfered graph.
* @param graph The HyperGraph instance to be written to.
* @param atomFinder Return handles of existing atoms so that they are not stored
* again or under a different handle. This parameter can be null in which
* case existing atoms (with the same handle) are overwritten and equivalents
* (same "information import", but different handle) are ignored.
*
* @return The set of atoms that where stored.
* @throws ClassNotFoundException
*/
public static Set<HGHandle> writeTransferedGraph(final Json atom,
final HyperGraph graph,
final Mapping<Pair<HGHandle, Object>,
HGHandle> atomFinder)
throws ClassNotFoundException
{
// TODO - here we assume that the types don't differ, but obviously they can
// and will in many cases. So this is a major "TDB".
// If something goes wrong during storing the graph and reading back
// an atom, the following will just throw an exception and the framework
// will reply with failure.
final RAMStorageGraph subgraph = decodeSubgraph(atom.at("storage-graph").asString());
final Map<String, String> typeClasses = Messages.fromJson(atom.at("type-classes"));
subgraph.translateHandles(getLocalTypes(graph, typeClasses));
Map<HGHandle, Object> objects = new HashMap<HGHandle, Object>();
Set<HGHandle> ignoreAtoms = translateAtoms(graph, subgraph, objects, atomFinder);
return storeObjectsTransaction(graph, subgraph, objects, ignoreAtoms);
}
示例2: iterator
import org.hypergraphdb.util.Mapping; //导入依赖的package包/类
public Iterator<Pair<HGPersistentHandle, Object>> iterator()
{
return new FilterIterator<Pair<HGPersistentHandle, Object>>(wrapped.iterator(),
new Mapping<Pair<HGPersistentHandle, Object>, Boolean>()
{
public Boolean eval(Pair<HGPersistentHandle, Object> n)
{
// We might not have the atom here...which may be all right with a distributed DB
if (n == null)
return false;
return n.getSecond() instanceof HGPersistentHandle[] &&
shouldIgnore(n.getFirst(), (HGPersistentHandle[])n.getSecond());
}
}
);
}
示例3: analyze
import org.hypergraphdb.util.Mapping; //导入依赖的package包/类
public Map<String, Set<HGQueryCondition>> analyze()
{
redflags.clear();
final Map<Class<?>, Mapping<Object, Boolean>> dispatch =
new HashMap<Class<?>, Mapping<Object, Boolean>>();
if (options.containsKey(INTERSECTION_THRESHOLD))
dispatch.put(IntersectionQuery.class, analyzeJoin);
if (options.containsKey(SCAN_THRESHOLD))
dispatch.put(PredicateBasedFilter.class, analyzePredicateFilter);
HGUtils.visit(query, new Mapping<Object, Boolean>() {
public Boolean eval(Object x)
{
if (x == null)
return Boolean.TRUE;
Mapping<Object, Boolean> f = dispatch.get(x.getClass());
if (f != null)
f.eval(x);
return Boolean.TRUE;
}
});
return redflags;
}
示例4: resolveEntities
import org.hypergraphdb.util.Mapping; //导入依赖的package包/类
public static Json resolveEntities(final HyperNodeJson node, final Json top)
{
final IdentityHashMap<HGHandle, Json> done = new IdentityHashMap<HGHandle, Json>();
return traverse(top, new Mapping<Json, Boolean>() {
public Boolean eval(Json j)
{
if (j.isObject())
{
Json resolved = Json.object();
for (String name : j.asJsonMap().keySet())
{
Json value = j.at(name);
HGHandle entityHandle = node.getEntityInterface().entityReferenceToHandle(node, value);
if (entityHandle != null)
{
value = done.get(entityHandle);
if (value == null)
{
value = node.get(entityHandle);
done.put(entityHandle, value);
resolved.set(name, value);
}
}
}
j.with(resolved);
}
return true;
}
});
}
示例5: TransferGraph
import org.hypergraphdb.util.Mapping; //导入依赖的package包/类
public TransferGraph(HyperGraphPeer thisPeer,
HGTraversal traversal,
HGPeerIdentity target,
Mapping<Pair<HGHandle, Object>, HGHandle> atomFinder)
{
this(thisPeer, traversal, target);
this.atomFinder = atomFinder;
}
示例6: directoryRecurse
import org.hypergraphdb.util.Mapping; //导入依赖的package包/类
static void directoryRecurse(File top, Mapping<File, Boolean> mapping)
{
File[] subs = top.listFiles();
if (subs != null)
{
for(File sub : subs)
{
if (sub.isDirectory())
directoryRecurse(sub, mapping);
mapping.eval(sub);
}
mapping.eval(top);
}
}
示例7: PredicateBasedRAFilter
import org.hypergraphdb.util.Mapping; //导入依赖的package包/类
/**
* <p>Construct a <code>PredicateBasedFilter</code>, filtering the result
* set of a given query based on a <code>HGQueryCondition</code>.
* </p>
*
* @param query The base query that is being filtered.
* @param predicate The filtering predicate.
*/
public PredicateBasedRAFilter(final HyperGraph graph,
final HGQuery<T> query,
final HGAtomPredicate atomPredicate)
{
this.graph = graph;
this.query = query;
this.predicate = new Mapping<T, Boolean>() {
public Boolean eval(T h)
{
return atomPredicate.satisfies(graph, (HGHandle)h);
}
};
}
示例8: PredicateBasedFilter
import org.hypergraphdb.util.Mapping; //导入依赖的package包/类
/**
* <p>Construct a <code>PredicateBasedFilter</code>, filtering the result
* set of a given query based on a <code>HGQueryCondition</code>.
* </p>
*
* @param query The base query that is being filtered.
* @param predicate The filtering predicate.
*/
public PredicateBasedFilter(final HyperGraph graph,
final HGQuery<T> query,
final HGAtomPredicate atomPredicate)
{
this.graph = graph;
this.query = query;
this.predicate = new Mapping<T, Boolean>() {
public Boolean eval(T h)
{
return atomPredicate.satisfies(graph, (HGHandle)h);
}
};
}
示例9: FilteredRAResultSet
import org.hypergraphdb.util.Mapping; //导入依赖的package包/类
public FilteredRAResultSet(HGRandomAccessResult<T> searchResult,
Mapping<T, Boolean> predicate,
int lookahead)
{
super(searchResult, predicate, lookahead);
rs = searchResult;
}
示例10: prim
import org.hypergraphdb.util.Mapping; //导入依赖的package包/类
public void prim(HGHandle start,
final HGALGenerator adjencyGenerator,
Mapping<HGHandle, Double> weight,
Map<HGHandle, HGHandle> parentMatrix)
{
}
示例11: findObjectPattern
import org.hypergraphdb.util.Mapping; //导入依赖的package包/类
@SuppressWarnings("unchecked")
static HGSearchResult<HGHandle> findObjectPattern(final HyperNodeJson node, Json pattern, final boolean exact)
{
if (exact)
return findExactObject(node, pattern);
pattern = pattern.dup();
Mapping<HGHandle, Boolean> themap = null;
if (!exact)
{
final Collection<ItemMap> maps = collectMaps(pattern);
if (!maps.isEmpty())
{
themap = new Mapping<HGHandle, Boolean>()
{
public Boolean eval(HGHandle h)
{
Json j = node.get(h);
for (ItemMap m : maps)
{
j = m.eval(j);
if (j.isNull())
return false;
}
return true;
}
};
}
}
HGSearchResult<HGHandle> [] propertyCandidates = new HGSearchResult[pattern.asJsonMap().size()];
int i = 0;
for (Map.Entry<String, Json> e : pattern.asJsonMap().entrySet())
{
for (JsonProperty prop : findAllProperties(node, e.getKey(), e.getValue()))
System.out.println(node.get(prop.getName()) + " = " + node.get(prop.getValue()));
propertyCandidates[i] = node.findPropertyPattern(e.getKey(), e.getValue());
if (!propertyCandidates[i].hasNext())
{
for (int j = i; j >= 0; j--)
HGUtils.closeNoException(propertyCandidates[j]);
propertyCandidates = null;
break;
}
i++;
}
if (propertyCandidates != null)
{
HGSearchResult<HGHandle> rs = new PipedResult<List<HGHandle>, HGHandle>(
new CrossProductResultSet<HGHandle>(propertyCandidates),
new AbstractKeyBasedQuery<List<HGHandle>, HGHandle>()
{
public HGSearchResult<HGHandle> execute()
{
And and = hg.and(hg.type(JsonTypeSchema.objectTypeHandle), hg.link(getKey()));
return node.find(and);
}
},
true
);
if (themap == null)
return rs;
else
return new FilteredResultSet<HGHandle>(rs, themap, 0);
}
else
return (HGSearchResult<HGHandle>) HGSearchResult.EMPTY;
}
示例12: testComplexEntity
import org.hypergraphdb.util.Mapping; //导入依赖的package包/类
@Test
public void testComplexEntity()
{
// The following is an entity that has some other entities nested in it, at various
// levels. It also has some values that should be immutable and not duplicated in
// the database.
Json object = Json.read(T.getResourceContents("/hgtest/mjsonapp/data1.json"));
node.add(object);
Assert.assertTrue(object.has("hghandle"));
// Nested entity should also have a handle:
traverse(object, new Mapping<Json, Boolean>() { public Boolean eval(Json j)
{ if (j.isObject() && j.has("entity")) Assert.assertTrue(j.has("hghandle")); return true; }
});
// There is still more work to do on spec-ing the entity management. The decision
// to forbid entities inside a value doesn't seem to square well with some sensible
// use cases, like having an array of entities as a property of an enclosing entity -
// the array is immutable to that prevents us from having entities inside it, which doesn't
// make much sense. We need different rules before this and other similar tests can be completed.
// ... and be added as a separate atom
// Assert.assertNotEquals(object.at("owns").at(0).at("hghandle"), object.at("owns").at(1).at("hghandle"));
// except when there is a primary key match for this kind of entity
// Assert.assertNotEquals(object.at("spouse").at("hghandle"), object.at("watching").at(0).at("star"));
// Nested value should not have handle
Assert.assertFalse(object.at("stats").has("hghandle"));
/* reopen();
Json fromdb = node.get(he);
fromdb = traverse(fromdb.dup(), new RemoveProp("hghandle"));
Assert.assertTrue(fromdb.equals(object));
fromdb = node.get(he);
Assert.assertEquals(traverse(fromdb.dup(), new RemoveProp("hghandle")), object);
Assert.assertEquals(node.add(object), he); */
List<Json> L = node.getAll(
Json.object("entity", "user",
"username", "morbo",
"stats", Json.object("friends", 25))).asJsonList();
System.out.println(L.size());
// HGHandle h1 = node.match(Json.object("sound", true), false);
// HGHandle propHandle = node.findProperty("stats", h1);
Assert.assertTrue(L.size() >= 1);
Assert.assertTrue(node.getAll(
Json.object("entity", "user",
"username", "morbo",
"stats", Json.object("sound", true))).asJsonList().size() >= 1);
}
示例13: translateBatch
import org.hypergraphdb.util.Mapping; //导入依赖的package包/类
/**
* Returns the number of new replacements to be made, i.e. the number of
* new atom equivalents found. On the other hand, the substitutes parameter
* may contain identity mapping for atoms that are both in the RAMStorageGraph
* and in the HyperGraph - we only want to track those in order to ignore them
* when the RAMStorageGraph is finally written locally.
*/
private static int translateBatch(HyperGraph graph,
Set<HGHandle> batch,
RAMStorageGraph subgraph,
Map<HGHandle, Object> objects,
Mapping<Pair<HGHandle, Object>, HGHandle> atomFinder,
Map<HGHandle, HGHandle> substitutes)
{
int replacements = 0;
for (HGHandle atom : batch)
{
// HGPersistentHandle [] layout = subgraph.getLink(atom);
// Object object = null;
// graph.getStore().attachOverlayGraph(subgraph);
// try
// {
// HGHandle [] targetSet = new HGHandle[layout.length-2];
// System.arraycopy(layout, 2, targetSet, 0, layout.length-2);
// HGAtomType type = graph.get(layout[0]);
// object = type.make(layout[1],
// new ReadyRef<HGHandle[]>(targetSet),
// null);
// }
// finally
// {
// graph.getStore().detachOverlayGraph();
// }
Object object = readAtom(atom, graph, new HGAtomResolver<HGAtomType>(graph), subgraph);
HGHandle existing = atomFinder == null ? null :
atomFinder.eval(new Pair<HGHandle, Object>(atom, object));
if (existing != null)
{
substitutes.put(atom, existing);
if (!existing.equals(atom))
replacements++;
}
else
objects.put(atom, object);
}
return replacements;
}
示例14: translateAtoms
import org.hypergraphdb.util.Mapping; //导入依赖的package包/类
private static Set<HGHandle> translateAtoms(final HyperGraph graph,
final RAMStorageGraph subgraph,
final Map<HGHandle, Object> objects,
final Mapping<Pair<HGHandle, Object>,
HGHandle> atomFinder)
{
//
// This algo must find all local equivalents of the transferred atoms. The basic operation
// that does this is the 'translateBatch' method - to keep the locking system usage
// low, the whole thing is done in batches of 200 atoms. The atoms are the "roots" of the storage
// graph that we translating. The idea is the construct a runtime instance of each root atom
// and try to find a local equivalent using the 'atomFinder' parameter (if not null). When
// a local equivalent is found, its handle replaces all occurrences of the root handle from
// the 'subgraph'. Because that replacement process may change the content of links that
// the atomFinder couldn't initially map to local versions, but that it could potentially
// map, we repeat the whole process again until no more subgraph are made.
//
// Perhaps this could be coded in a more efficient way, but the goal for now is to get it to
// work first.
//
// Boris
//
final Map<HGHandle, HGHandle> substitutes = new HashMap<HGHandle, HGHandle>();
final Set<HGHandle> batch = new HashSet<HGHandle>();
final Map<HGHandle, HGHandle> currentChanges = new HashMap<HGHandle, HGHandle>();
final int [] replacements = new int[1];;
do
{
replacements[0] = 0;
currentChanges.clear();
for (HGPersistentHandle theRoot : subgraph.getRoots())
{
if (!substitutes.containsKey(theRoot))
batch.add(theRoot);
if (batch.size() < 200)
{
continue;
}
else
{
graph.getTransactionManager().transact(new Callable<Object>() {
public Object call()
{
replacements[0] += translateBatch(graph, batch, subgraph, objects, atomFinder, currentChanges);
batch.clear();
return null;
}
},
HGTransactionConfig.DEFAULT);
}
}
graph.getTransactionManager().transact(new Callable<Object>() {
public Object call()
{
replacements[0] += translateBatch(graph, batch, subgraph, objects, atomFinder, currentChanges);
return null;
}
},
HGTransactionConfig.DEFAULT);
subgraph.translateHandles(currentChanges);
substitutes.putAll(currentChanges);
} while (replacements[0] > 0);
return substitutes.keySet();
}
示例15: MapCondition
import org.hypergraphdb.util.Mapping; //导入依赖的package包/类
public MapCondition(HGQueryCondition condition, Mapping<?, ?> mapping)
{
this.cond = condition;
this.mapping = mapping;
}