last day (15 days later) » 

11:13 AM
0
Q: Return the list of users in prolog

Flávio JardimMy goal is return the list of X users with T tags in common with a specific user and one of them is mandatory. I have this Knowledge Base: %node(Id, Name, ListOfTags) node(1,ana,[nature,cat,dog,sw,csharp]). node(11,antonio,[cat,nature,car,sport,city]). node(22,isabel,[nature,cat,test,dog,c]). no...

 
And what attempt have you made to solve it so far? What wasn't working?
 
@Enigmativity i tried but i have no idea how to achieve my goal. Any suggestion is welcome. Thank you!
 
How would you solve it by hand?
 
@lambda.xy.x i tried to get the tags of the main user, then using findall to get all users with same tags and the validate if have any group of user that match with the NumberOfUsers and if they have the mandatory tag. Like I said i’m tried a resolution but I’m stuck.
 
@FlávioJardim - Please show us what you have tried.
@FlávioJardim - I also don't understand what you mean by "biggest_group" if you are mandating the NumberOfUsers.
 
11:13 AM
@Enigmativity you right, the word biggest have no sense here. Its just a list of users.
@Enigmativity my question was edited with what i’ve tried/have.
 
@FlávioJardim - And my question re the number of users?
 
@Enigmativity the final result must be a list with NumberOfUsers length with a MandatoryTag otherwise returns a empty list.
 
@FlávioJardim have you tried your predicate in a Prolog environment? It has syntax errors and mentions undefined predicates. Can you also check if your database is correct? Multiple people have the same id but an id is supposed to be unique. Moreover, I would expect the query suggest_group(ana, 3, cat, LGroup) to fail, not succeed with LGroup = []. Is this really what you intended?
 
@lambda.xy.x you right abou the id's and i fixed them. I don't have implement the predicate suggest_group/4. It's just de definition and my difficult is achieve the goal of that predicate. The predicate user_X_common_Tags/3 it's just an auxiliar predeicate that find the tags of the main user and itersect them withanother user.
 
If I copy paste the definition of user_X_common_Tags/4 into SWI Prolog, I get the error message: ERROR: user://3:656:6: Syntax error: Unbalanced operator. Does it work on your machine?
 
11:13 AM
@lambda.xy.xi just edit the predicate user_X_common_tags/3. Tried now please: user_X_common_tags(ana, cat, Users) for example.
 
You might want to debug a bit more. If I try ?- user_X_common_tags(ana, cat, X). I get X = [ana, antonio, isabel, john, maria]. but maria does not have a cat.
Btw: in findall(X, Pred, Xs) the argument Xs should not appear in Pred (or X).
 
@lambda.xy.x exactly. that's my problem. Beaside i must introduce the argument NumberOfUsers. The idea like i said its return a list with N NumberOfUsers with the mandatory tag. For example, if the the NumberOfUsers = 2 and in the base knowledge only exists one user with mandatory tags, the result must be empty List.
 
Number of users is just the length of the list of users - that should be easy as soon as you have the list.
Btw. you are not using the information about the mandatory tag. Perhaps try replacing the intersection by stating that the MandatoryTag must be in Tags? This only works if the predicate should fail if the interesection is empty.
 
@lambda.xy.x yes the MandatoryTag and the NumberOfUsers are the keys on this problem. They must bem considered and that's my difficulty.
 
Try node(_, User, Tags2), intersection(Tags1, Tags2, Commontags), member(MandatoryTag, Commontags) or just node(_, User, Tags2), member(MandatoryTag, Tags2).
Btw. if you didn't know about member - you should be able to write it yourself. An element is member of a list, if it's the first element of the list or if it is member of the other elements.
 
11:13 AM
@lambda.xy.x thanks. I tried with node(_, User, Tags2), intersection(Tags1, Tags2, Commontags), member(MandatoryTag, Commontags) and when i make the question user_X_common_tags(ana, cat, Users) the result it's Users = [ana, antonio, isabel]. The MandatoryTags its Ok and now must be considered the NumberOfUsers.
@lambda.xy.x i edit the question with more progress but its not functional. My difficulty now it’s considered the NumberOfUser argument.
 
@FlávioJardim - Is it your intent that isabel has two cat tags?
 
@Enigmativity no. It was my mistake. I fixed it.
 

last day (15 days later) »