OrientDB Find vertex is linked with a list of another vertex - orientdb

i am discovering OrientDB and i have a problem :
I have two vertex definition :
Product
Criterion
And one Edge definition:
- IsRelatedToEdge
Thanks to IsRelatedToEdge, I can link one product to many criterion
In my example, i have populated the database with 5 products
shoe-1
shoe-2
shoe-3
hat-1
hat-2
and 4 criterions :
blue
red
hat
shoe
Then I linked products with criterion this way:
shoe-1 <=> shoe
shoe-1 <=> blue
shoe-2 <=> shoe
shoe-2 <=> red
shoe-3 <=> shoe
shoe-3 <=> blue
hat-1 <=> shoe
hat-1 <=> blue
hat-2 <=> hat
hat-2 <=> red
so we have 2 blue shoe, 1 blue hat, 1 red shoe, 1 red hat.
I cannot figure out how to find all blue shoes.
EDIT : I have found a 'solution' but it doesn't looks good :
select from Product where
in('IsRelatedToEdge')[name="blue"].size() = 1 and
in('IsRelatedToEdge')[name="shoe"].size() = 1

IMO, the power of OrientDB lies in the graph abilities, and queries on a table/index do not really leverage this. I feel the best way to do this query is to get the shoe criterion, then get all of the products that have an edge to the criterion. From those products (ie all the shoes), you can now filter for ones that also have an edge to the blue criterion. One way to write this is as follows...
select *
from (select expand(both('IsRelatedToEdge')) from Criterion where name = 'Shoe')
let $blue_criterion = (select from Criterion where name = 'Blue')
where both('IsRelatedToEdge') contains $blue_criterion[0]
Taking the above thought process further though, you could consider rearranging your data for better/easier querying. For example, you could make a Hat and Shoe class that are both subclasses of Product. That way to query on shoes, you query against the Shoe vertex class only. Similarly, you can make different criterion subclass, such as Color. To get blue shoes with such a config, the query would like the following...
select *
from Shoes
let $blue_criterion = (select from Color where name = 'Blue')
where both('IsRelatedToEdge') contains $blue_criterion[0]
You could even make more specific edges to take this a step further.

After studying neRok'solutions, i came at this solutions:
select expand($result)
let
$crit1 = (select expand(out('IsRelatedToEdge')) from Criterion where name='blue'),
$crit2 = (select expand(out('IsRelatedToEdge')) from Criterion where name='shoe'),
$result = intersect($crit1, $crit2)
With this kind of query, I can add another criterion.
Imagine if we have anotehr criterion named adidas and i want to have all blue adidas shoes :
select expand($result)
let
$crit1 = (select expand(out('IsRelatedToEdge')) from Criterion where name='blue'),
$crit2 = (select expand(out('IsRelatedToEdge')) from Criterion where name='shoe'),
$crit3 = (select expand(out('IsRelatedToEdge')) from Criterion where name='adidas'),
$result = intersect($crit1, $crit2, $crit3)

Related

how do i create a filter of planned size from a population?

i'd like to create a list with planned size.Following this example,i do not want all the women of "people" population,but only (for example) 50.Suggestions?Thanks for the help
List women = filter( people, p -> p.gender == FEMALE );
it would be something like this
List women = filter(people,p -> p.gender == FEMALE ).subList(0,50);
be careful that the number 50, you need to be sure that you actually have 50 possible women, otherwise you will get error.

Calculated field affected the Grand Total in Tableau

Used a calculated field by using the window_max and window_min functions:
IF
([eCPM]) = WINDOW_MAX(([eCPM]))
THEN "Least efficient" ////Red
ELSEIF [eCPM] = WINDOW_MIN(([eCPM]))
THEN "Most efficient CPM" ///Green
ELSE "Neither" ///Gray
END
But this also affected my Grand Total. I don't want any coloring in totals. How to handle this? (Solved)
Since my calculation is based upon eCPM, can only this column be highlighted as green rather entire row, without highlighting media cost and visits green as well?
Since my calculation is based upon eCPM, can only this column be highlighted as green rather entire row, without highlighting media cost and visits green as well?
You just need to "wrap" you if statement with another one in order to handle the grand total using size which returns the number of rows in the partition.
Using the superstore you can create a calculated field like this:
// Handle Grand Total
IF SIZE() = 1 THEN "Neutral"
// Handle all other "rows"
ELSE
IF sum([Sales]) = WINDOW_MAX(sum([Sales]))
THEN "Green"
ELSEIF sum([Sales]) = WINDOW_MIN(sum([Sales]))
THEN "Red"
ELSE "Neutral"
END
END
The result could look like this:

Handling forward 1:n relationships with drools

I'm trying to write a rule that applies on a set of facts based on the content of another fact. I have simplified the problem to a House with Rooms. Let's say we have something like:
House(id);
Room(id, houseId, floor, side, paint);
Now, if I want to trigger a rule on all the Houses with all Rooms in left side painted on green I would write something like:
rule "Left side 1st floor green"
when
$h: House()
forall($r: Room(houseId=$h.id, floor==1, side=="left")
Room(id == $r.id, paint == "green"))
then
//Do whatever on rule triggering
end
But what if the objects in the working memory are organized in this way:
House(id, List<> roomIds);
Room(id, floor, side, paint);
How can I write a foreach condition (or any other approach) to make the same consideration on the rooms for a given house? Does it make sense or should I better try to reorganize my objects in advance to have the relationship expressed the other way around?
Thanks
Assuming in House the List<> roomIds is a List of Room.id(s), then you can do something like:
rule "Left side 1st floor green"
when
$h: House(/* .. conditions for specific house? .. */)
$r : Room($h.roomIds contains id, floor==1, side=="left", paint == "green")
then
//Do whatever on rule triggering
end
However this is a bit unefficient, and I do agree as others replied, changing a bit the business/data model would make writing this kind of rule more idiomatic and more efficient. For example if the House did have the list of Rooms, you can also use OOPath to navigate as desired the structure.
According to your rule, you do not have houses with rooms. According to what you have defined you have houses in your working memory and you have rooms in your working memory and you try to match these.
Why don't you have a List of Rooms in your House? That would make much more sense:
House(houseId, List<Room> rooms)
Room(roomId, floor, side, paint)
Then your rule would be:
rule "Left side 1st floor green"
when
$houses : House ($rooms : rooms, $houseId : houseId)
$room : Room ($roomId : roomId, floor==1 && side=="left" && paint == "green") from $rooms
then
//Rule would trigger for each room left side 1st floor green rooms
System.out.println("House "+$houseId+" has following left side 1st floor green room: "+$roomId);
end

SSRS expression for calculation using a specific value

I've attempted to create an expression which should calculate when a field equals 'Mid' and another equals 'Red' then calculate a percentage based on a field / specific number.
Here are my attempts so far:
=count(IIF(Fields!loc.Value="Mid" AND Fields!Status.Value ="Red",1,Nothing)) / count(Fields!Total.Value / 500) *100
=IIF(Fields!loc.Value="Mid" AND Fields!Status.Value="Grey",(FormatPercent (Count(Fields!Total.Value) / 500 ,0))
Expected results from the calculation would be a percentage: 34.83% (to two DP)
Loc field contains locations: Mid, Lon, Manc, Newc etc etc
Status field contains colours for statuses: Red, Green, Blue, Yellow etc etc Total field contains 'total' values for locations.
Neither seem to work and I'm getting myself confused. Once this one part is done, I can then add multiple locations and colours too.
Supposing a dataset like this:
Loc Status Total
Mid Red 100
Mid Red 200
Lon Blue 90
Manc Yellow 50
And you want to calculate the percentage of occurrences where Loc = "Mid" and Status = "Red" Using an expression like this:
=COUNT(
IIF(Fields!Loc.Value = "Mid" and Fields!Status.Value = "Red",Fields!Loc.Value,Nothing)) /
COUNT(Fields!Loc.Value,"DataSetName")
Replace DataSetName by the actual name of yours.
You will get 2/4 = 0.5 (50%) if you format the cell to a percentage number.
Hope it helps.

Write the relational algebra expression to find the manufacturers (maker) of printers which are not colour (color) printers

Product(model, maker, type)
PC(model, speed, ram, hd, price)
Laptop(model, speed, ram, hd, screen, price)
Printer(model, color, type, price)
so far iv got this: σ Printer = 'color' (Product join model = model Printer)
Some help please
You want to select your maker first, then you can join the product and printer table on model. After that put in your selection on Printer.color = false.
This code should work:
π maker (Product ⨝ π model (σ color = false (Printer)))