-
Thank you for the getting started document. It looks like you depend on the external predicates for output (printing)? How could I do something even more basic like create some facts:
And then issue a query:
and assign (1) the first result to a variable or (2) all results to a list? I don't understand a few of the logic rules (below) in the example. I see that
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Have you run the GuanTest project? I recommend you do. Those rules are from GuanTest. You can see what the test outputs in the console when you run the program. Also, did you run the GuanExamples project? Why don't you create rules and run queries using it? That is what it is for. I will add another external predicate impl that employs a GroundPredicateResolver that will bind a value to a result that can be used as a variable in the containing rule. For now, the Examples project is very simplistic. The external predicates do simple arithmetic on provided values, then write something to the Windows (or Linux) console, then return true (they are BooleanPredicateResolvers). You can try out your rules and query by modifying the existing GuanExamples project: Program.cs: var logicsRules2 = new List<string>
{
"person(adam)",
"person(betty)",
"person(carl)",
"person(dan)",
};
Module module2 = Module.Parse("person", logicsRules2, null);
var queryDispatcher2 = new GuanQueryDispatcher(module2);
// This requires changing the behavior of RunQueryAsync function. See below (will push the changes, but the idea is that you make changes to the GuanExamples project to learn how to use Guan.
await queryDispatcher2.RunQueryAsync("person(?p)", 4); // output => answer: (p='adam'),(p='betty'),(p='carl'),(p='dan') GuanQueryDispatcher.cs public async Task RunQueryAsync(string queryExpression, int maxResults = 1)
{
// Required QueryContext instance.
QueryContext queryContext = new QueryContext();
// Required ModuleProvider instance. You created the module used in its construction in Program.cs.
ModuleProvider moduleProvider = new ModuleProvider();
moduleProvider.Add(module_);
// The Query instance that will be used to execute the supplied logic rule, queryExpression arg.
Query query = Query.Create(queryExpression, queryContext, moduleProvider);
// Execute the query.
// result will be () if there is no answer/result for supplied query (see the simple external predicate rules, for example).
if (maxResults == 1)
{
// Gets one result.
Term result = await query.GetNextAsync();
Console.WriteLine($"answer: {result}");
}
else
{
// Gets multiple results, if possible, up to supplied maxResults value.
List<Term> results = await query.GetResultsAsync(maxResults);
Console.WriteLine($"answer: {string.Join(',', results)}");
}
} |
Beta Was this translation helpful? Give feedback.
-
Just shipped an updated GuanExamples project which should help answer your questions and make it easier to play with and learn Guan. Thanks again for all the questions. It's been very helpful and others will benefit. Cheers |
Beta Was this translation helpful? Give feedback.
-
Hi! I just noticed that "retract" was added to the development branch. That is wonderful! How do I add that branch of Guan to my C# project? I was wondering if version 1.0.4 on NuGet may have "retract" since the dates appear to line up. |
Beta Was this translation helpful? Give feedback.
Have you run the GuanTest project? I recommend you do.
Those rules are from GuanTest. You can see what the test outputs in the console when you run the program.
Also, did you run the GuanExamples project? Why don't you create rules and run queries using it? That is what it is for.
I will add another external predicate impl that employs a GroundPredicateResolver that will bind a value to a result that can be used as a variable in the containing rule. For now, the Examples project is very simplistic. The external predicates do simple arithmetic on provided values, then write something to the Windows (or Linux) console, then return true (they are BooleanPredicateResolvers).
You can try out y…