How to calculate similarity between users

There are edges (person_name_direct) from one user to all the other users.

user_id: string @index(term) .
person_name_direct: uid @reverse .
city_name_direct: uid @reverse .

{
set {
_:user1 <city_name_direct> _:user2 (score=30) .
_:user1 <person_name_direct> _:user2 (score=40) .
_:user1 <user_id> “abc” .
_:user2 <user_id> “xyz” .
_:user3 <user_id> “pqr” .
_:user1 <city_name_direct> _:user3 (score=50) .
_:user1 <person_name_direct> _:user3 (score=50) .
_:user2 <city_name_direct> _:user3 (score=60) .
_:user3 <person_name_direct> _:user3 (score=90) .
}
}

How can i get cumulative score (sum of person_name_direct and city_name_direct) from one user to all the other user’s ? Let me know if i need to change the way i store values in order to get the cumulative score’s

You can take a look at this https://docs.dgraph.io/query-language/#sum-and-avg

In your query you will create a block that will fetch these values to variables and then you can sum them up. And return the second block.

See this e.g from Pawan Cond in func not work as I suppose

Hi MichelDiz,
I have tried

{
everyone(func: eq(user_id, “12345”)) {
person_name_direct @facets(person_score as score){
personScore as math(person_score)
}
city_name_direct @facets(city_score as score){
cityScore as math(city_score)
}
personScores as sum(val(personScore))
cityScores as sum(val(cityScore))
cumScore as math(personScores + cityScores)
cs: val(cumScore)
}
}

But this gives me sum of all the person_score’s instead of between one user to other user. How can i maintain the cumulative score between each pair of user’s

Maybe this could help https://docs.dgraph.io/query-language/#k-shortest-path-queries

or you may need to merge in steps. Using the blocks to solve what you want and then in the end return the results.

Example: You want to add the punctuation of each user. Hence return these values separately and compare.

But Dgraph would not have a comparison tool. Except “k-shortest”. I had understood that you wanted only the sum of everything for each user. But you want the sum of the score and a comparison.

This part of your query that finds the user_id. I would recommend you to use the UID of Dgraph and look for everyone (func: uid (0x12345)) {- Because it is much faster and does not generate load and other side effects.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.