How to query a Labeled relation by the label in HypergraphDB

41 views
Skip to first unread message

Mayukh Das

unread,
Jan 17, 2018, 10:24:27 PM1/17/18
to HyperGraphDB
How do we create a query with LinkCondition with filter on label (if the link was created via HGRel object)?

Any help will be extremely appreciated since I am new to using the HypergraphDB framework.

Borislav Iordanov

unread,
Jan 18, 2018, 1:45:17 AM1/18/18
to hyperg...@googlegroups.com
Hi there,

The HGRel label is in 1-1 association with the HGRelType (the atom type of your HGRel), so if you have added a relation like so:

graph.add(new HGRel(target1, target2, target3), relationType)

then you can find it with:

graph.findOne(hg.and(hg.type(relationType), hg.link(target1, target2))

Cheers,
Boris

On Jan 17, 2018, at 10:14 PM, Mayukh Das <mayu...@gmail.com> wrote:

How do we create a query with LinkCondition with filter on label (if the link was created via HGRel object)?

Any help will be extremely appreciated since I am new to using the HypergraphDB framework.

--
You received this message because you are subscribed to the Google Groups "HyperGraphDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hypergraphdb...@googlegroups.com.
To post to this group, send email to hyperg...@googlegroups.com.
Visit this group at https://groups.google.com/group/hypergraphdb.
For more options, visit https://groups.google.com/d/optout.

Moditha Hewasinghage

unread,
Jan 31, 2018, 12:23:39 PM1/31/18
to HyperGraphDB
Hi,

You can refer to this question I made which i found the solution.

https://stackoverflow.com/questions/48211435/is-there-a-way-to-query-for-specific-hglink-name-in-hypergraphdb

Basically the HGRel is missing a setter for the "name". Either change the source or create a subclass with all setters

Borislav Iordanov

unread,
Feb 2, 2018, 12:21:41 AM2/2/18
to hyperg...@googlegroups.com
Hi,

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

Mayukh Das

unread,
Feb 11, 2018, 8:20:57 PM2/11/18
to HyperGraphDB
Thanks this was of extreme help.
Reply all
Reply to author
Forward
0 new messages