static CommonProjections get(final HyperGraph graph) { CommonProjections cp = M.get(graph.getLocation()); if (cp == null) { cp = new CommonProjections(); cp.put( "localName", new HGProjection() { public int[] getLayoutPath() { return null; } public String getName() { return "localName"; } public HGHandle getType() { return graph.getTypeSystem().getTypeHandle(String.class); } public void inject(Object atomValue, Object value) { ((OWLClass) atomValue).setLocalName((String) value); } public Object project(Object atomValue) { return ((OWLClass) atomValue).getLocalName(); } }); M.put(graph.getLocation(), cp); } return cp; }
/** * Adds the type to the type system for a graph. * * @param graph The graph to which to add the type system. */ public static void initType(HyperGraph graph) { ValueWithUncertaintyElemFactoryType<?, ?> type = new ValueWithUncertaintyElemFactoryType(); HGPersistentHandle typeHandle = graph.getHandleFactory().makeHandle(); graph .getTypeSystem() .addPredefinedType(typeHandle, type, ValueWithUncertaintyElemFactory.class); }
/** * Return the one true type condition out of a conjunction of multiple conditions that constrain * by type in one way or another. The method returns null if no type is actually specified already * (this means all type conditions in the passed in set are using variables). If there is an * inconsistency b/w two type conditions so that the result set should be really empty, the method * returns and AtomTypeCondition with a null reference (i.e. "no type possible"). * * @param graph * @param bytype * @return */ public static Pair<AtomTypeCondition, TypeConditionAggregate> reduce( HyperGraph graph, Set<TypeCondition> bytype) { HGHandle typeHandle = null; TypeConditionAggregate taggr = new TypeConditionAggregate(); for (TypeCondition c : bytype) { if (hg.isVar(c.getTypeReference())) { taggr.watchTypeReference(c); // ((Var<?>)c.getTypeReference()); continue; } HGHandle th = null; if (c.getTypeReference().get() instanceof Class<?>) { th = graph.getTypeSystem().getTypeHandleIfDefined(c.getTypeReference().getClass()); if (th == null) { taggr.watchTypeReference(c); continue; } } else th = (HGHandle) c.getTypeReference().get(); if (typeHandle != null) { typeHandle = findMostSpecific(graph, typeHandle, th); if (typeHandle == null) // are they incompatible? return new Pair<AtomTypeCondition, TypeConditionAggregate>( new AtomTypeCondition((Ref<?>) null), taggr); } else typeHandle = th; } // At this point we have possibly found one most specific type handle // specified as part of the // conjunction and possibly several conditions with variable type or // unresolved Java class (which // for all intents and purposes are like variables right now. if (typeHandle != null) return new Pair<AtomTypeCondition, TypeConditionAggregate>( new AtomTypeCondition(hg.constant(typeHandle)), taggr); else return null; }
/** * Adds a PEdgeView given a FEdge * * @param edge the edge * @return a new PEdgeView or existing one */ public PEdgeView addEdgeView(FEdge edge) { if (edgeViewMap.containsKey(edge)) return edgeViewMap.get(edge); if (check_edge_consistency) { Object s = graph.get(edge.getSource().getHandle()); if (!(s instanceof HGLink)) System.err.println("Impossible PEdgeView - source is not HGLink: " + edge); if (!graph .getIncidenceSet(edge.getTarget().getHandle()) .contains(edge.getSource().getHandle())) System.err.println("Impossible PEdgeView - target is not pointed by source: " + edge); } PEdgeView edge_view = new PEdgeView(edge, this); addToEdgeLayer(edge_view); edgeViewMap.put(edge, edge_view); fireGraphChanged(new GraphViewEdgesAddedEvent(this, new FEdge[] {edge})); return edge_view; }
/** * Constructor * * @param comp HGViewer in which this GraphView is dispalyed * @param db HyperGraph to be viewed * @param nodes Nodes to be shown * @param edges Edges to be shown */ public GraphView(HGViewer comp, HyperGraph db, Collection<FNode> nodes, Collection<FEdge> edges) { this.graph = db; this.setIdentifier(db.getLocation()); nodeViewMap = new HashMap<FNode, PNodeView>(nodes.size()); edgeViewMap = new HashMap<FEdge, PEdgeView>(edges.size()); viewComponent = comp; initialize(nodes, edges); }
/** * Recalculates and reapplies all of the edge appearances. The visual attributes are calculated by * delegating to the EdgePainter member of the current visual style. */ public void applyEdgeAppearances() { for (PEdgeView edgeView : edgeViewMap.values()) { FNode node = edgeView.getEdge().getSource(); HGHandle h = graph.getTypeSystem().getTypeHandle(node.getHandle()); EdgePainter p = getVisualStyle(true).getEdgePainter(h); if (p == null) p = def_edge_painter; p.paintEdge(edgeView); } }
public static void loadAll(HyperGraph graph) { graph.getTransactionManager().beginTransaction(); try { for (Map.Entry<String, HGPersistentHandle> e : syntacticPredicates.entrySet()) { if (graph.get(e.getValue()) == null) graph.define(e.getValue(), new SyntacticPredicate(e.getKey())); } graph.getTransactionManager().endTransaction(true); } catch (Throwable ex) { try { graph.getTransactionManager().endTransaction(false); } catch (Throwable t) { t.printStackTrace(System.err); } if (ex instanceof RuntimeException) throw (RuntimeException) ex; else throw new RuntimeException(ex); } }
@Override protected void calculateCommonFriends(int id1, int id2) throws Exception { Set<HGHandle> friendsOf1 = getFriendsOf(id1); Set<HGHandle> friendsOf2 = getFriendsOf(id2); friendsOf1.retainAll(friendsOf2); for (HGHandle hgHandle : friendsOf1) { printCommonFriend(id1, id2, (Long) database.get(hgHandle)); } }
/** * Returns an array with the adjacent edges of a given nodes * * @param node The node * @param incoming if true, includes all incoming edges * @param outgoing if true, includes all outgoing edges * @return */ public FEdge[] getAdjacentEdges(FNode node, boolean incoming, boolean outgoing) { if (node == null || !nodeViewMap.containsKey(node)) return new FEdge[0]; HGHandle nH = node.getHandle(); IncidenceSet handles = graph.getIncidenceSet(nH); Set<FEdge> res = new HashSet<FEdge>(); for (HGHandle h : handles) { FNode incNode = new FNode(h); if (!nodeViewMap.containsKey(incNode)) continue; if (outgoing) { FEdge e = new FEdge(node, incNode); if (edgeViewMap.containsKey(e)) res.add(e); } if (incoming) { FEdge e = new FEdge(incNode, node); if (edgeViewMap.containsKey(e)) res.add(e); } } Object o = graph.get(nH); if (o instanceof HGLink) { HGLink link = ((HGLink) o); for (int i = 0; i < link.getArity(); i++) { FNode incNode = new FNode(link.getTargetAt(i)); if (!nodeViewMap.containsKey(incNode)) continue; if (outgoing) { FEdge e = new FEdge(incNode, node); if (edgeViewMap.containsKey(e)) res.add(e); } if (incoming) { FEdge e = new FEdge(node, incNode); if (edgeViewMap.containsKey(e)) res.add(e); } } } return res.toArray(new FEdge[res.size()]); }
private NodePainter getPainter(HGHandle h, boolean return_default) { NodePainter p = getVisualStyle(true).getNodePainter(h); if (p == null && return_default) p = def_node_painter; if (p != null) return p; try { HGHandle typeH = graph.getTypeSystem().getTypeHandle(h); return getPainter(typeH, true); } catch (HGException ex) { // do nothing // the node handle pointed to some statically // defined HGHandleFactory.makeHandle() // with no value return def_node_painter; } }
public static void deleteAll(HyperGraph graph) { // // We can't do a single transaction here, because we are potentially deleting // a lot of relations and BDB will run out of locks. // List<HGHandle> all = hg.findAll(graph, hg.type(SyntacticPredicate.class)); for (HGHandle h : all) { try { graph.remove(h); } catch (RuntimeException ex) { ex.printStackTrace(System.err); } } }
@Override protected long getNodeName(HGHandle node) { return graphDB.get(node); }
/** * Adds the type to the type system for a graph. * * @param graph The graph to which to add the type system. */ public static void initType(HyperGraph graph) { EinsteinTensorElemType<?, ?, ?> type = new EinsteinTensorElemType(); HGPersistentHandle typeHandle = graph.getHandleFactory().makeHandle(); graph.getTypeSystem().addPredefinedType(typeHandle, type, EinsteinTensorElem.class); }
/** * Adds the type to the type system for a graph. * * @param graph The graph to which to add the type system. */ public static void initType(HyperGraph graph) { ComplexElemFactoryType<?, ?> type = new ComplexElemFactoryType(); HGPersistentHandle typeHandle = graph.getHandleFactory().makeHandle(); graph.getTypeSystem().addPredefinedType(typeHandle, type, ComplexElemFactory.class); }
public Object from(Json x) { return graph.getHandleFactory().makeHandle(x.asString()); }
public Object from(Json x) { return graph.getStore().getIndex(x.asString()); }