OrientDB traverse using intersection condition for node-property - compare

Please apologize, I'm new on stackoverflow and completely new to OrientDB. I have the following, simple test-structure in OrientDB:
different connected nodes, which have a list of tags as property
I want to show only the part of the graph (nodes with their edges), which have a intersection at the tags. This should be for this example, the highlighted red node and the smooth red once with the edge PRAESENTIERT_BEI.
In Neo4j, it is very easy. You just look for the start-node, traverse over all connections and compare the property with a filter like the following code example:
MATCH (n:ConferenceSerie)
MATCH p = n-[*]-m WHERE FILTER(x IN n.flag WHERE x IN m.flag)
RETURN p
But I have no idea how to handle it on OrientDB. I thought it could be done with TRAVERSE, and the intersect() function, but I have no idea how to compare the property of two nodes.
Is there any chance to create a SQL-query which shows the subgraph?
Thanks in advance.

I used the field tags as EmdeddedList of String
create class A extends V
create property A.tags EmbeddedList String
create class B extends V
create property B.tags EmbeddedList String
create class C extends V
create property C.tags EmbeddedList String
create class D extends V
create property D.tags EmbeddedList String
create class E1 extends E
create class E2 extends E
create class E3 extends E
insert into A(tags) values(["http"]) //#12:0
insert into B(tags) values(["www","cs","at"]) //#13:0
insert into C(tags) values(["www","papers","com"]) //#14:0
insert into D(tags) values(["https"]) //#15:0
create edge E1 from 12:0 to 13:0
create edge E2 from 14:0 to 13:0
create edge E3 from 14:0 to 15:0
Try the following query
select expand(list) from (select $d as list from e
let $a=(select in.tags as tags from $parent.$current unwind tags),
$b=(select out.tags as tags from $parent.$current unwind tags ),
$c=intersect($a.tags,$b.tags),
$d=unionAll(#rid,out.#rid,in.#rid)
where $c.asList().size()>0)

Related

Merge 2 object lists in java

i have two lists listA and listB of type object
ListA[name=abc, age=34, weight=0, height=0] data collected from excel sheet
ListB[name=null, age=0, weight=70, height=6] data collected from database
Now i want to combine both the lists into a single list
MergedList[name=abc, age=34, weight=70, height=6]
Note: my obj class has more than 15 properties so adding each property one by one using getProperty() will be time-consuming.is there a better way?
Convert them to a Map where the key is the name of the object ( you denoting the elements as name=abc suggests they are name/value pairs ).
Map<String,MyMysteriousObject> converted = list.stream().collect( Collectors.toMap(MyMysteriousObject::getName, Function.identity() ) );
( replace the getName with what ever function you use to get the name of your object )
And then just merge the maps. How to merge maps is described here for example.
While at it, consider replacing the List with Map in your entire code. Will surely save a lot of work elsewhere too.
But if you have to have a list again, just List<MyMysteriousObject> resultList = new ArrayList<>(resultMap);

Is there a way to create a unordered list with subitems from 1 content-type

I would like to create a organogram like:
https://codepen.io/bernardoantunes/pen/inrbh using 2sic Content.
I would like to create a content-type 'organogram' with the following fields:
Title as String
Parent as Entity (of type Organogram)
Description as String
Link as Hyperlink
Using this content-type i would add some elements where child elements could be created.
for example:
- Root
- Child 1 (Root is selected in the Parent field)
- Child 2 (Root is selected in the Parent field)
- Child 3 (Child 2 is selected in the Parent field)
Could this be done using 2sic content App?
I created the content-type and added some elements. Created a razor template and then it gives an error.
operator '==' can not be applied to operands of type System.Collections.Generic.List and ToSic.SexyContent.DynamicEntity
Razor template:
#using Connect.Koi;
#{
var first = AsDynamic(Data["Default"]).First();
var all = AsDynamic(Data["Default"]);
}
<div>#first.Title</div>
var children = all.Where(x => x.parent == first).ToList();
<div>#children.Count</div>
Basically the AsDynamic(...) creates wrapped entity-objects, whereas ...parent gives you a list of related items (because it could have more than 1 parent). If this is the code you want to use, I suggest 1 things.
On the .parent (which should probably be .Parent) use the [0] or .FirstOrDefault() so it's .Parent.FirstOrDefault() == first - remember to enable LINQ by #using System.Linq
Don't compare the AsDynamic objects, because they will be different objects. Better compare the id using .EntityId or something.
So you're resulting compare will probably be .Parent[0].EntityId == first.EntityId.
What I don't like about your solution is the idea, that the first item in the Default-list will somehow be the important one. This doesn't feel right, but I don't know your whole solution...

Reading Values from a Bag of Tuples in pig

I have UDF output as :-
Sample records:-
({(Todd,1),(Todd,1),(Todd,1),(Todd,1),(Todd,1),(Todd,5),(Todd,10),(Todd,20),(Todd,10),(Todd,10),(Todd,10),(Todd,10),(Todd,10),(Todd,10)})
({(Jon,1),(Jon,1),(Jon,1),(Jon,1),(Jon,1),(Jon,5),(Jon,10),(Jon,20),(Jon,10),(Jon,10),(Jon,10),(Jon,10),(Jon,5),(Jon,20),(Jon,1)})
Schema for UDF:- name:chararray(1 single column)
Now i want to read this bag of tuples and generate output as :-
Todd,240
Jon,422
The output of the UDF i stored in a temp file and read it back using different schema as:-
D = LOAD '/home/training/pig/pig/UDFdata.txt' AS (B: bag {T: tuple(name:chararray, denom:int)});
After that i am trying to use foreach loop and reference dot notation to find the sum.
X = foreach D generate B.T.name,SUM(B.T.denom);
2017-03-04 13:52:59,507 ERROR org.apache.pig.tools.grunt.Grunt: ERROR
1128: Cannot find field T in name:chararray,denom:int Details at
logfile: /home/training/pig_1488648405070.log
Can you please let me know how to find it? I am new to Apache Pig so not sure how it traverse in Bag of Tuples and find sum.
GROUP the dataset on name before performing SUM.
FLATTEN the bag to perform GROUP.
flattened = FOREACH D GENERATE FLATTEN(B);
dump flattened;
...
(Todd,10)
(Todd,10)
(Jon,1)
(Jon,1)
....
Then, GROUP them on name
grouped = GROUP flattened by name;
dump grouped;
(Jon,{(Jon,1),(Jon,20),(Jon,5),(Jon,10),(Jon,10),(Jon,10),(Jon,10),(Jon,20),(Jon,10),(Jon,5),(Jon,1),(Jon,1),(Jon,1),(Jon,1),(Jon,1)})
(Todd,{(Todd,10),(Todd,10),(Todd,10),(Todd,10),(Todd,10),(Todd,10),(Todd,20),(Todd,10),(Todd,5),(Todd,1),(Todd,1),(Todd,1),(Todd,1),(Todd,1)})
And apply SUM() over the result
final_sum = FOREACH grouped GENERATE group, SUM(flattened.denom);
dump final_sum;
(Jon,106)
(Todd,100)

PIG regex extract then filter the unnamed regex tuple

I have a string as:
[["structure\/","structure\/home_page\/","structure\/home_page\/headline_list\/","structure\/home_page\/latest\/","topic\/","topic\/location\/","topic\/location\/united_states\/","topic\/location\/united_states\/ohio\/","topic\/location\/united_states\/ohio\/franklin\/","topic\/news\/","topic\/news\/politics\/","topic\/news\/politics\/elections\/,topic\/news\/politics\/elections\/primary\/"]]
I want to regex_extract_all to turn it into elements in a tuple and sepereated by ",". Then I need to filter out the ones don't contain structure and location.
However, I got an error that can't filter regex type. Any idea?
By the way, the ending goal is to parse out the longest hierarchy like (topic|news|politics|elections|primary)
update the script:
data = load load '/web/visit_log/20160303'
USING com.twitter.elephantbird.pig.load.JsonLoader('-nestedLoad') as json:map[];
a = foreach data generate json#section as sec_type;
b = foreach act_flt GENERATE ..host, REGEX_EXTRACT_ALL(act_type, 'topic..(?!location)(.*?)"') as extr;
store b into /user/tad/sec_hir
The syntax for filter matches seems incorrect.The data doesn't seem to have () in it.
c = filter b by not extr matches '(structure|location)';
Try changing this to
c = filter b by not (extr matches 'structure|location');

ID/Key definitions in EMF (Meta) Models

I'm stuck with a very basic problem regarding EMF, here's what i've got.
EClass A:
aID : EInteger (Key: true)
EClass B:
bID : EInteger (Key: true)
EClass C:
Reference refA: to elements of A, containment: true, EKeys: aID, 0 .. n
Reference refB: to elements of B, containment: true, EKeys: bID, 0 .. n
Now here's the problem. In both my a and b list I'd like to have IDs from 0 to n. However, when I do this, I get the message:
The ID '1' of 'A' collides with that of 'B'
I hope my problem is described clearly. Does anyone know what I'm doing wrong? Thanks!
An EAttribute which is set as "ID" should be unique resource-wide. If you want to reference elements using a myReference[name="SomeName"] construction then you should use eKeys, then the eKeyed attribute should have a unique value within a reference.
I am under the impression you defined "aID" and "bID" as "ID's whereas that's not what you really want here.
That could be resolved using OO hierachy. You just need to extend A and B from a common Abstract class that contains the id attribute and it setted as ID in emf properties.
regards