I'm fairely new to HypergraphDB and was running few tests to see how things are working and encountered this problem. I have created a hypergraph with different HGRel and I want to get the ones with a specific name and was trying to use the following code
List<HGRel> r = hg.getAll(graph, hg.and(hg.type(HGRel.class), hg.eq("name", "XXX")));
basically I want to find all hyperedges that is named "XXX" but unfortunately I am getting this error
java.lang.RuntimeException: org.hypergraphdb.HGException: Could not find projection for 'name' in HG type a5edd585-2d5c-4555-8fdf-f9954bd35fe9 for HGRel
at org.hypergraphdb.transaction.HGTransactionManager.ensureTransaction(HGTransactionManager.java:324)
at org.hypergraphdb.query.cond2qry.ExpressionBasedQuery.<init>(ExpressionBasedQuery.java:812)
at org.hypergraphdb.HGQuery.make(HGQuery.java:174)
at org.hypergraphdb.HyperGraph.find(HyperGraph.java:1524)
at org.hypergraphdb.HGQuery$hg$10.call(HGQuery.java:1753)
at org.hypergraphdb.HGQuery$hg$10.call(HGQuery.java:1)
at org.hypergraphdb.transaction.HGTransactionManager.transact(HGTransactionManager.java:400)
at org.hypergraphdb.transaction.HGTransactionManager.ensureTransaction(HGTransactionManager.java:327)
at org.hypergraphdb.HGQuery$hg.getAll(HGQuery.java:1746)
I can always get all HGRel and filter on the application but I was wondering what I am doing wrong in here. Thank you in advance
The setter is not there intentionally. It’s not a mutable property of the HRel. When you create HGRel atoms you are normally supposed to add them with a HGRelType which itself will hold the label.
What’s probably happening in your case is that you are storing the HGRel as a Java bean and not using the HGRelType at all. This works as a strategy but the particular API (HGRelType, HGRel, HGRelTypeConstructor) is not intended to be used this way.
What I’d suggest instead is to create your own generic LabeledLink class where the name is a bean property and then index by it so you can query more efficiently:
public class LabeledLink extends HGPlainLink { private String label;
public LabeledLink(HGHandle…targets) { super(targets); }
public void setLabel(String label) …
public String getLabel() {return label; } }
HGHandle labeledType = graph.getTypeSystem().getTypeHandle(LabeledLink.class); graph.getIndexManager().register(new ByPartIndexer(labeledType, “label”);
Cheers, Boris