Discussion Forum

Compare two attributes using conditions

I am looking for a condition using rule in which i can compare two different attributes like this:
an entity named symptomsFound contains attribute symptoms entered by user and second attribute named identifiedSymptoms in other entity which is contained in a dataset where based on symptoms disease in mentioned in another column.

so i am writing a condition in which symptoms entered by a user will be compared with identifiedSymptoms in dataset available and based on that i can get the expected disease from the dataset to be represented on my graph.

the condition i wrote for this is:

symptomFound sub entity,
owns symptoms,
plays results:symptomsFoundInUser;

results sub relation,
    relates symptomsFoundInUser,
    relates patient;

disease-based-on-symptoms-in-user sub relation;

disease-based-on-symptoms sub rule,
    $symptoms = $identifiedSymptoms;
}, then {
    $symptoms has $identifiedDisease isa disease-based-on-symptoms-in-user;

Also a part of dataset:
itching skin_rash nodal_skin_eruptions dischromic _patches
skin_rash nodal_skin_eruptions dischromic _patches
itching nodal_skin_eruptions dischromic _patches
shivering chills watering_from_eyes
continuous_sneezing chills watering_from_eyes

itching skin_rash nodal_skin_eruptions dischromic _patches,Fungal infection,dermatologist
continuous_sneezing shivering chills watering_from_eyes,Allergy,allergist / immunologist
stomach_pain acidity ulcers_on_tongue vomiting cough chest_pain,GERD,gastroenterologist

With all this i am not able to write correct rule and relation because i can’t commit the transaction. Please let me know how to do this.

Hi everyone!
Please let me know where i am wrong in above posted query. Any help would be appreciated!

Hi @vaticle
Please let me know if any help can be provided on above posted question. Thanks in advance!:smiley:

Best to allow the community a bit of time (more than a day or two) before bumping your own post!

Have you read the docs at docs.grakn.ai? There it states that you’re only allowed to make specific types of rules:

  1. infer a new relation then { (arole: $x) isa myrelation; }
  2. add an existing attribute: then { $x has $a; }
  3. add a potentially new attribute then {$ x has name "bob"; }
disease-based-on-symptoms sub rule,
    $symptoms = $identifiedSymptoms;
}, then {
    $symptoms has $identifiedDisease isa disease-based-on-symptoms-in-user;

youre suggested rule does not conform to the requirements.
Also, how is the system supposed to know what $symptoms and identifiedSymptoms are? You need to provide a more specific when clause. I recommend reading the docs more thoroughly to get the basics nailed down :slight_smile:

@joshua thanks for responding!..I read the doc again and got the error in writing rule. All i want to know here is how can i compare the values of two different attributes present inside different entities? Is this possible with grakn or not?

In my case:
diseases sub entity,
owns identifiedSymptoms,
owns identifiedDisease;

symptomFound sub entity,
owns symptoms;

If i want to check the values present in symptoms attribute is same or not as the values in identifiedSymptoms, how could i go with the rule in gql file.
Like i mentioned $symptoms = $identifiedSymptoms , with this i am not able to check their values are same or not?

yes you use = to check the equality and != to check inequality of two attributes by value.

But right now that’s completely disconnected. As the examples hopefully show (probably not clearly enough) you’ll have to specify more information, something like;

when {
  $x isa symptomFound, has symptom $a;
  $y isa disease, has identifiedSymptom $b;
  $a = $b;
} then {

you can’t create an entity in the then of the rule - you’ll either create a relation or connect the attributes to the existing thing concepts.