GithubHelp home page GithubHelp logo

jsakamoto / csharpprolog Goto Github PK

View Code? Open in Web Editor NEW

This project forked from johnpool/csharpprolog

45.0 15.0 20.0 4.29 MB

A C# implementation of Prolog (port from https://sourceforge.net/p/cs-prolog )

Home Page: https://jsakamoto.github.io/Prolog-on-Browser/

License: GNU Lesser General Public License v3.0

C# 99.69% Smarty 0.30% Batchfile 0.01%

csharpprolog's Introduction

CSharpProlog NuGet Package Build status

A C# implementation of Prolog

// PM> Install-Package CSProlog -pre
using System;
using Prolog;

class Program
{
    static void Main(string[] args)
    {
        var prolog = new PrologEngine(persistentCommandHistory: false);

        // 'socrates' is human.
        prolog.ConsultFromString("human(socrates).");
        // human is bound to die.
        prolog.ConsultFromString("mortal(X) :- human(X).");

        // Question: Shall 'socrates' die?
        var solution = prolog.GetFirstSolution(query: "mortal(socrates).");
        Console.WriteLine(solution.Solved); // = "True" (Yes!)
    }
}

Installation

Run the following command from the Visual Studio Package Manager Console to install the latest version:

Install-Package CSProlog

The NuGet page can be found here:
https://www.nuget.org/packages/CSProlog/#

Solution Layout

CSProlog

Prolog Engine

CSProlog.Core.Test

Unit Tests

PL.NETCore

Dotnet Core Console Interactive Interpreter (tested in linux and windows)

PLd

DOS Console Interactive Interpreter

PLw

Windows Forms Example

PLx

An example of how to use the engine within another Program

For more documents

Earlier release documents can be found in README (2007-2014).pdf.

Release Notes

v.6.0.0

  • BREAKING CHANGE: Remove "SAMPLES, TESTING & EXPERIMENTAL" predefined predicates. (including CHAT-80 support)
  • Fix: "help" predefined predicate dose not work.
  • Enhance: GetAllSolutions can work with null file name.

v.5.0.0.1

  • Support: .NET Standard 1.4 (.NET Core) and UWP

v.5.0.0

  • BREAKING CHANGE: Remove dependency of "System.Windows.Forms".
  • NuGet package release

Older versions

Earlier release notes can be found in README (2007-2014).pdf.

License

GNU LGPL v.3

csharpprolog's People

Contributors

johnpool avatar jsakamoto avatar poolofthought avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

csharpprolog's Issues

"CsPrologHelp.txt" file which has been mentioned in "ShowHelp" method is missing.

"help" predicate can resolve with the output below:

File CsPrologHelp.txt contains the help texts and a description of how to re-create help.

But "CsPrologHelp.txt" file does not exist anywhere.

If I try to recreate "CsPrologHelp.txt" file, but it means I should also build recreating help text feature.

Therefore, at this time, I'll eliminate the output of "help" predicate above.

GetAllSolutions only works if you pass in a file

GetAllSolutions is supposed to be one of the methods that allows the prolog engine to be utilized from other programs. However, it only works if the program calling it actually sends a file path in as a parameter.

The parameter is allowed to be passed in as null, and when it is null the method is probably expected to simply use the whatever the current contents of the database are at the time. Instead, when there is no file specified (aka null in the first parameter) the method returns no answers.

Good news:
I've already got this fixed and have unit tests set up for it as well (I actually found the bug after I created the test and I couldn't get it to pass). On researching it I realized there is no conditional around the reset call in this method [same for his xml counterpart method]. So it was resetting the database in preparation to read in from the file even when no file was specified.

Documentation for CSProlog

Hi, I was wondering if there is any documentation for this module. I can't seem to find any anywhere.

Query result includes variable name?

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?

Can not add the same root fact twice by "ConsultFromString()" method.

@Thriliriel wrote:

Hello.

I liked this idea a lot! I am facing a problem where i cannot add the same root fact twice. For example, if we use the readme example:

prolog.ConsultFromString("human(socrates).");`

I am not able to add another human, like, for example:

prolog.ConsultFromString("human(socrates).");
prolog.ConsultFromString("human(aristoteles).");

It raises the error: Predicate 'human/1' is already defined in...

Is there a way to avoid that?

Thanks!

Originally posted by @Thriliriel in #33 (comment)

.NET Core support

Hello,

It's not really an issue but a question.

I just found your library and it seems really great :-)

Have you planned to adapt this library in .NET Core ?

Thanks you!

CHAT folder missing

There is mention in CSProlog\bootstrap.cs of a CHAT folder that should be part of the repo. If you type chat it tries but can't find the file.

Is this something that was intentionally left out? Maybe couldn't be found? I think if the example code can't be found it's probably better removed from the comments also. It sure would be nice if we could find it and put it back in (assuming it wasn't left out on purpose), but the link mentioned in the comments is also dead. :(

Note: this is my first putting of an issue on someone else's repo so please forgive me if I've gone about it wrong. I'm open to correction.

Create more Issues for Desired Unit Tests

I think we should probably get a unit test built around each of the predicates called out below. My thought is we could either create an issue for each one or maybe one for each group.

From this link:
https://www.cis.upenn.edu/~matuszek/Concise%20Guides/Concise%20Prolog.html

Built-in Predicates
Prolog has a large number of built-in predicates. The following is a partial list of predicates which should be present in all implementations.

Input predicates
read(X) -- Read one clause from the current input and unify it with X. If there is no further input, X is unified with end_of_file.
get(X) -- Read one printing character from the current input file and unify the ASCII code of that character (an integer) with X.
get0(X) -- Read one character from the current input file and unify the ASCII code of that character with X.
see(File) -- Open File as the current input file.
seen -- Close the current input file.

Output predicates
write(X) -- Write the single value X to the current output file.
writeq(X) -- Write X with quotes as needed so it can be read in again.
tab(N) -- Write N blanks to the current output file.
nl -- Write a newline to the current output file.
put(X) -- Write the character whose ASCII value is X to the current output file.
tell(File) -- Open File as the current output file.
told -- Close the current output file.

Control predicates
X ; Y -- X or Y. Try X first; if it fails (possibly after being backtracked into), try Y.
(X -> Y) -- If X, then try Y, otherwise fail. Y will not be backtracked into.
(X -> Y ; Z) -- If X, then try Y, else try Z. X will not be backtracked into.
not X -- (Sometimes written +X or not(X)) Succeed only when X fails.
true -- Succeed once, but fail when backtracked into.
repeat -- Always succeed, even when backtracked into.
fail -- Never succeed.
! -- (Pronounced "cut".) Acts like true, but cannot be backtracked past, and prevents any other clauses of the predicate it occurs in from being tried.
abort -- Return immediately to the top-level Prolog prompt.

Database manipulation predicates
assert(X) -- Add X to the database. For syntactic reasons, if X is not a base clause, use assert((X)).
asserta(X) -- Add X to the database in front of other clauses of this predicate.
assertz(X) -- Add X to the database after other clauses of this predicate.
retract(X) -- Remove X from the database. For syntactic reasons, if X is not a base clause, use retract((X)).
abolish(F,A) -- Remove all clauses with functor F and arity A from the database.
clause(X,V) -- Find a clause in the database whose head (left hand side) matches X and whose body (right hand side) matches V. To find a base clause, use true for V.
save(F) -- Save the entire program state on File F (usu. as a binary image).
restore(F) -- Replace the program state with the one on File F.

Arithmetic predicates
X is E -- Evaluate E and unify the result with X.
X + Y -- When evaluated, yields the sum of X and Y.
X - Y -- When evaluated, yields the difference of X and Y.
X * Y -- When evaluated, yields the product of X and Y.
X / Y -- When evaluated, yields the quotient of X and Y.
X mod Y -- When evaluated, yields the remainder of X divided by Y.
X =:= Y -- Evaluate X and Y and compare them for equality.
X == Y -- Evaluate X and Y and succeed if they are not equal.
...and similarly for >, <, >=, =<.

Listing and debugging predicates.
listing(P) -- Display predicate P. P may be a predicate name, a structure of the form Name/Arity, or a bracked list of the above.
trace -- Turn on tracing.
notrace -- Turn off tracing.
spy P -- Turn on tracing when predicate P is called. P may be a predicate name, a structure of the form Name/Arity, or a non-bracked list of the above.
nospy P -- Turn off spying for P.
nospyall -- Turn off all spypoints.
debug -- Enable spypoints (allow them to initiate tracing.).
nodebug -- Disable spypoints (without removing them).
Tracing -- Control over tracing is very system-dependent, but is probably like this:
Enter key -- Single-step to next line of trace.
h -- Provide help on tracing commands.
s -- (On a CALL) Skip over this call.
l -- Leap without tracing to the next spypoint.
n -- Turn off tracing.

  • -- Set a spypoint here.
    [missing (see if it was in link and just removed during copy paste) Remove the spypoint here.

Trace terminology: CALL is the initial entry to a predicate; EXIT is a successful return; REDO is when it is backed into for another answer; FAIL is when it finds no more solutions. A sequence of calls may be viewed as forming a chain.

Tests
atom(X) -- Succeed if X is an atom (an empty list is considered an atom).
atomic(X) -- Succeed if X is an atom or number.
number(X) -- Succeed if X is a number.
integer(X) -- Succeed if X is an integer.
float(X) -- Succeed if X is a real number.
var(X) -- Succeed if X is unbound (a non-instantiated variable).
nonvar(X) -- Succeed if X is bound.
X == Y -- Succeed if X and Y are identical (but do not unify them).
X == Y -- Succeed if X and Y are not identical.

PLw Project Needs some Attention

I ran the window app included in the solution and I couldn't even make sense of what it was trying to do. Also almost all of the menu items are there for show - they don't actually do anything.

It should be rewritten to make more sense and perform basic functionality in a way that makes sense.

Enhancing collaborability

It's kinda hard to contribute to this project at this point. Mostly because you cannot just open it in a IDE and run the tests without modifications.
At least by being on Linux and open this in Rider IDE. It requires adjusting of encoding (looks like source files are not in UTF-8) and second most important by having latest(nor specified which version to be used) . NET Core SDK unable to build and run tests from cli or IDE.

Documentation

Hi.
Is there any documentation or examples on how to tie prolog with C#? For instance, how to create a predicate that is, in fact a C# function reference?
Thank you

Font and Console Colors Should Not be Modified w/o Users Permission

The DOS and NETcore (command line / interpreter) versions automatically change their console background to white and the font to a darker color. It has been agreed that it is preferable to let the user maintain their chosen OS color theme instead.

An optional extra element of this issue is to either add a switch to the command line that sets up a dark or light theme or to add a predicate to the implementation. Adding a switch when launching is probably the best choice.

Best way to make the PrologEngine available in an app?

Hi folks,

I'm fairly new to C#. I'd like to integrate PrologEngine prolog = new PrologEngine(persistentCommandHistory: false); into my Xamarin.Forms application in such a way that the variable prolog is easily available to query and modify the knowledge database. Does this mean a global variable? A repository? What is the easiest way of doing this? What is the best practice?

-david

Chat and Chat80 still listed in help predicate listing

Chat just doesn't want to go away! Related to #3.

If you type "help" you get a list of predicates. Two of those mentioned are chat/0 and chat-80*. Since we took out the rest of the chat stuff we probably need to take that out too.

How can a fact be queried ?

like

query('what is your name', 'majid').
?- query('what is your name', Name).

Unable to get value of Name variable

Create and publish v.6 package.

The v.6 CSharpProlog NuGet package will contains these fixing.

  • Fix #5: "help" predefined predicate dose not work
  • Fix #3: CHAT folder missing (remove all samples, testing, and experimental predefined predicates)

Especially fixing #3 has breaking change, so I will increment major version number for this new package.

Fix a big mistake - GitHub default branch configuration (and branch strategy)

I'm sorry to I changed Gitub default branch configuration of this repository .

image

I had not understand what about GitHub default branch configuration.

Plan

I'll create a new branch at HEAD commit that named "vnext/master".

And I'll reconfigure GitHub default branch configuration to set up "vnext/master" is default branch.

After that, I expect all tasks such as creating feature branches, making pull requests, and so on, are based on "vnext/master" branch.

Q. Why don't you use master branch?

Because this repository is forked version of John Pool's original repository.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.