Mapping amount of properties - mapping

i want to map 2 different Ontologies A and B. But the classes i want to map have a different amount of object properties.Lets say A equals b. A is father and B is mother. class A:(gender, age, eyecolour, brother) class B:(age, gender, haircolour, sport)
the Union of A and B say C got:(gender, age, eyecolour, haircolour, sport) right? Is there any create statement in owL? or do i need to make the equvivalent to statement for the object properties. Is there any statement lets say if A got 2 brothers, create the object property x in B.

OWL classes aren't classes in the object-oriented programming sense, properties don't "belong" to classes in the sense that methods belong to classes (in many OO programming languages). When you say that the domain of a property P is the class C, it means that whenever you have an assertion
P(x,y)
you can infer that
x is a C
If you assert that the
P domain A
Q domain A
R domain B
S domain B
T domain B
and then assert that
C equivalentClass (A union B)
then you'll be able to infer that
P domain C
Q domain C
R domain C
S domain C
T domain C
Since, e.g.,
P(x,y)
implies
x is an A
which in turn implies that
x is a (A union B)
which implies that
x is a C
So C is a domain of P. I think that's what you're meaning when you say that "the class C has property P."

Related

Matching Nodes by relationship based on Ancestor properties of each Node in neo4j

In a scenario where assemblies of Objects have subassemblies of subassemblies of Objects:
Assembly 1
A:Object{name:ABC} is PART_OF B:Object{name:DEF} is PART_OF C:Object{name:GHI}
Assembly 2
D:Object{name:JKL} is PART_OF E:Object{name:MNO} is PART_OF F:Object{name:PQR} is PART_OF G:Object{name:STU}
and some component object of Assembly 1 is connected to Assembly 2
C is JOINED_TO G
How to MATCH all Objects where any part of the assembly chain in Assembly 1 has a given name property that are JOINED_TO Objects where any part has a given name property
my guess would be:
MATCH ob1:Object{name:DEF} - [:PART_OF*] -> ob2:Object - [:JOINED_TO] - ob3:Object <- [:PART_OF*] - ob4:Object{name:PQR}
RETURN ob2, ob3
but no amount of 'asciiart' graph play gets me what I expect
ob2 ob3
------------
C G
I used this to create your sample graph:
CREATE (A:Object{name:'ABC'})-[:PART_OF]->(B:Object{name:'DEF'})-[:PART_OF]->(C:Object{name:'GHI'}),
(D:Object{name:'JKL'})-[:PART_OF]->(E:Object{name:'MNO'})-[:PART_OF]->(F:Object{name:'PQR'})-[:PART_OF]->(G:Object{name:'STU'})
CREATE (C)-[:JOINED_TO]->(G)
And I used this to query the graph:
MATCH (ob1:Object{name:'DEF'}) - [:PART_OF*] -> (ob2:Object) - [:JOINED_TO] - (ob3:Object) <- [:PART_OF*] - (ob4:Object{name:'PQR'})
RETURN ob2, ob3
This correctly returns the two nodes with names 'GHI' and 'STU'.
This query will not return "C" or "G", because you never saved that to your graph. In your creation query "C" and "G" (and all the other single letters used) are variables for the nodes in question. Variables are not saved to the database, and they do not persist after a query has finished. They are for addressing things (nodes, relationships, values, etc) throughout the duration of a query, but not past it.
If you want a query to return "C" and "G" then you should save these as additional properties on the nodes, and return those properties in your RETURN.
Here's the documentation on variables from the Cypher developer guide.

Cypher WHERE NOT EXISTS with named variable

In a Neo4J database, I need to find a (complex) pattern with 3 named node (let's say a, b, c) and some other non-named nodes, but only if there is no node (say "x") that connects to a, b, and c.
I'd like to write something like :
MATCH (a:A)-<something>-(b:B)-<something>-(c:C)
WHERE NOT EXISTS ((a)--(x:X)--(b), (x)--(c) )
RETURN a, b, c
But I get "Variable x not defined". It would be easy if x was only forbidden if connected to (a) and (b). And NOT EXISTS (a)--(:X)--(b) AND NOT EXISTS (a)--(:X)--(c) is too strong.
Any ideas?
You should try MATCHing x:X and using it the WHERE:
MATCH (x:X), (a:A)-<something>-(b:B)-<something>-(c:C)
WHERE NOT EXISTS ((a)--(x)--(b), (x)--(c) )
RETURN a, b, c

Spring Data Neo4j 4 and primary indexes

I'm trying to understand how to correctly use primary indexes in SDN 4.
From the org.neo4j.ogm.annotation.Index javadoc:
Only one index per class hierarchy may be marked as primary.
Does it mean that if I have a following entity hierarchy:
B extends A
C extends A
I can't add into the both entities B and C the following index definition :
#Index(unique = true, primary = true)
private Long id;
This primary index can be only added to A or to B or to C entity ?
Or if I can add the primary index into the both of them ( B and C), can B.id and C.id hold the same value.. for example 1
Only one index per class hierarchy may be marked as primary.
This means you can have only 1 primary index in a class, or any of its super classes.
E.g. if you have following hierarchy:
class A
class B extends A
class C extends B
you can have only 1 index, in either A, B or C.
In your situation you can have either index in A, or B (or B and C).
The difference is
if the index is in A, you won't be able to create B and C with same id - constraint on A label will be created
if the index is in B and C you can create B and C with same id, because it will be 2 separate constraints on 2 separate labels.

Neo4j Exact Match Query to Only Specified Pattern

I'm working on a project modeling product use patterns and I'm having trouble identifying the best way to make an exact match to a single pattern
In the model I have several "product_pattern" nodes acting as the center or hub to several nodes representing various products. Each product node is unique and can be connected to any product_pattern. A series of product pattern nodes may look like:
--pattern_1
--- Product A
--- Product B
--- Product C
--pattern_2
--- Product A
--- Product B
--- Product C
--- Product D
--pattern_3
--- Product B
--- Product C
I would like to query the graph for product_patterns that use products B and C and ONLY B and C. If I just used:
Start b = node(16), c = node(37)
MATCH (b)<-[:PRODUCT_USED]-(n)-[:PRODUCT_USED]->(c)
RETURN n
I would have all product_patterns returned because they all have relationships to B and C. To Remove matches that have additional relationships from what I'm querying I foresee two strategies..
Create a property in each pattern node of product_pattern.num_products to use against a WHERE clause after the initial MATCH. In this case the num_products property would have to match '2' for nodes with relationships ONLY to B and C. My concern here is that I have to dig into each returned node for properties and popular products will make the return list much larger.
Create a WHERE NOT clause for every other product in the graph that I don't won't a relationship to... not ideal and most likely traversing the entire graph.
Are there any elegant ways to confirm that your query returns exactly the relationship match you ask for and not nodes that match your query but also have additional relationships?
Can you try this:
Start b = node(16), c = node(37)
MATCH (b)<-[:PRODUCT_USED]-(n)-[:PRODUCT_USED]->(c)
WHERE length((n)-[:PRODUCT_USED]->(c)) == 2
RETURN n

rails activerecord belongs_to problem - can't insert

Seems simple, but having an issue:
model A
belong_to :B
model B
has_many :A
database tables:
table A:
id,...,b_id
table B:
id,...
When trying to create a new A, I set (an existing) B by doing:
a.b = B
I get an error saying "b can't be blank"
Instead of doing a.b = B, do a.b_id = B.id.
Think about how your collection and parent-child relationships work. You can -as suggested- add the ID of the relevant B to your A, but you may alternatively want to say B.a[] = a which would add "a" to your the "a" collection of your object "B". That way the relationship is set up in a more intuitive way, oriented towards the parent object rather than the child.
You should also be able to do newA = B.as.build ('as' being the plural of a).
Of course your examples of 'A, a, B and b` are very confusing! In the future use 'customer' & 'order' or 'blog' & 'post' or anything but cryptic letters with no meaning.

Resources