Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query result includes variable name? #40

Open
d-vyd opened this issue Jan 24, 2022 · 7 comments
Open

Query result includes variable name? #40

d-vyd opened this issue Jan 24, 2022 · 7 comments

Comments

@d-vyd
Copy link

d-vyd commented Jan 24, 2022

The answer set for this query var solution = prolog.GetAllSolutions(null, query: "person(P), loc(P,bedroom)."); is:

Solution 1
P (atom) = adam

Solution 2
P (atom) = clara

Solution 3
P (namedvar) = P

Given the content of the database, there should only be two solutions. Why is "P" included and how can I avoid it? Do I need to check for the type (namedvar) or phrase my queries differently?

@jsakamoto
Copy link
Owner

Given the content of the database, there should only be two solutions.

I think so too.

Interestingly, the "Prolog on Broser" returned only two solutions.
That is the same as we expected.

image

At this time, I also have no ideas why the "GetAllSolutions()" method returned three answers in this situation.
I'll investigate this behavior.

@jsakamoto
Copy link
Owner

@d-vyd

I'm afraid but I was not able to reproduce the behavior that you reported.

My test code is here:

using Prolog;

var prolog = new PrologEngine(persistentCommandHistory: false);
prolog.ConsultFromString(
    "person(adam). " +
    "person(clara). " +
    "loc(P,bedroom).");

var solutions = prolog.GetAllSolutions(null, query: "person(P), loc(P, bedroom).");
Console.WriteLine($"Count of all solutions is {solutions.Count}");

for (var i = 0; i < solutions.Count; i++)
{
    var solution = solutions[i];
    Console.WriteLine(solution);
}

image

📁 PrologApp1.zip

Could you disclose your project file?
(You can attach your project zip file by drag and drop the file into this GitHub issue comment input field.)

@d-vyd
Copy link
Author

d-vyd commented Jan 27, 2022

jsakamoto,

I'm so glad you are maintaining this Prolog implementation! Thank you! In short, I must have inadvertently fixed whatever the problem was and you are welcome to close this thread and stop reading. However, I'd really like to learn more about what you are doing with C# and Prolog and learn from your experience.

I'm new to C#, Xamarin.Forms, and Prolog. I think Prolog might be a good fit for the logic (and perhaps game-state) of a turn-based text-only game. C# and Xamarin.Forms permit CSProlog to run with a modern GUI on a cell phone, which is fantastic. Is that also what you're doing?

I've attached my code and would welcome any advice you have to offer. I start the PrologEngine within a static class in App.xaml.cs and populate it in the same file. Where should this go within a Xamarin.Forms app? I employ the syntax Know.prolog.GetFirstSolution("assert(person(adam))."); because I read in the issues that there may be problems reusing the same predicate otherwise.

I query the Prolog database from MainPageViewModel.cs to display the result (names of characters/persons) inside a Picker. This is not working--and worse--Visual Studio does not report an error. When I noticed CSProlog was adding an extra solution item, I wrote a method, ExtractSolution (also in App.xaml.cs) to process the results and remove the variable name. But, when I exclude the check if (v.Type.ToString() != "namedvar" & v.Name.ToString() == var) the solution still looks correct. So, maybe the issue was a bug I inadvertently corrected.

mystery.zip

@jsakamoto
Copy link
Owner

@d-vyd Thank you for attaching the project file!

you are welcome to close this thread and stop reading.

Thank you for your kindness.

However, your project looks great to me, so I will try to figure out the project you attached as much as I can.

By the way, maybe, as you already know, my OSS activity is just my hobby, so I can not spend a lot of time on such activities, including responding to issues.

Maybe I can't reply this week at least because I have other issues that I have to answer to, but I hope for the success of your project!

@d-vyd
Copy link
Author

d-vyd commented Jan 30, 2022 via email

@d-vyd
Copy link
Author

d-vyd commented Jan 30, 2022

The Xamarin.Forms "Picker" is now working with Prolog and MVVM! I would still be interested in learning how you are using Prolog & C# whenever you have time.

@d-vyd
Copy link
Author

d-vyd commented Feb 16, 2022

@jsakamoto , I was not handling the SolutionSet object correctly. You can close this issue. Whenever you have free time, I'd love to learn whether and how you are using C# and Prolog together!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants