https://github.com/corymccartan/logic

Logic library, written in javascript.

https://github.com/corymccartan/logic

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.2%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Logic library, written in javascript.

Basic Info
  • Host: GitHub
  • Owner: CoryMcCartan
  • Language: JavaScript
  • Default Branch: master
  • Size: 180 KB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created about 10 years ago · Last pushed about 10 years ago
Metadata Files
Readme

README.md

LJS

Logical JavaScript

LJS is an ES6 logic library. It allows you to connect ordinary JavaScript objects with logical relationships, and then make queries about those relationships.

Installation

  • Bower: bower install lgs

Or you can download logic.js above.

Basic Usage

Data Types

LJS works with terms and variables. Terms are just normal JavaScript objects with some extra, hidden, LJS parameters attached. They are used to represent things and relationships. Things are represented by simple terms. They're just abstract objects with a label. Relationships are represented by compound terms. Compound terms take variables or simple terms and define some sort of relationship between them. For example: ```javascript let socrates = T("Socrates"); let plato = T("Plato");

socrates.is("human"); plato.is("human");

plato.has("teacher")(socrates); `` Simple terms are created using theTfunction. Compound terms are created by calling thehasandis` methods on a term.

But simply delcaring terms is not enough. We have to tell LJS that these relationships are facts. We do so by passing them to the facts function: javascript facts( socrates.is("human"), plato.is("human"), plato.has("teacher")(socrates) );

Queries

Once we've defined our facts, we can ask LJS questions about them, using the query function: ```javascript let who = V("who");

let answer = query( who.has("teacher")(socrates) ); `` Note the use of theV` function to create a new variable.

The query function does not return plato here. Instead, it returns a generator that yields all possible solutions to the query. Each solution is itself a Map that tells which variables are bound to which terms. So in the example above: javascript for (let solution of answer) { // solution is a Map solution.get(who) === plato; // true }

Each solution is also equipped with a function substitute that returns the original query term with the variables substituted. And every term has a toString method that turns it into a readable English sentence. So we can do: javascript for (let solution of answer) { let query_result = solution.substitute(); // is a term query_result.toString(); // "Plato has teacher Socrates" }

Rules

The real power of LJS becomes available when we start to define rules. Rules allow us to determine new relationships based on currently defined facts. For example: ```javascript let socrates = T("Socrates"); let X = V("X");

facts( socrates.is("human") );

given( X.is("human") ).then( X.is("mortal") );

let answer = query( socrates.is("mortal") );

for (let solution of answer) { solution.substitute().toString(); // "Socrates is mortal" } `` Thegivenfunction returns an object withandandthenmethods. Theand method allows us to add more predicates, or requirements, for the conclusion. Thethen` method defines the conclusions of the rule.

Sometimes, however, we just want a simple answer to a question, instead of a generator that returns variable bindings. LJS provides two global helper functions, is and does, for this purpose. Using the terms defined above, we can do the following: javascript +does(plato).have("teacher")(socrates); // 1 +is(socrates)("mortal"); // 1 +is(socrates)("immortal"); // 0

Global Configuration

If you'd like all of the global varialbes to be hidden behind a namespace instead of polluting the global object, simply set the _LOGIC_JS_NAMESPACE variable before you include LJS. For example, html <script> _LOGIC_JS_NAMESPACE = "logic"; </script> <script src="logic.js"></script> <script> window.T; // undefined logic.T; // defined </script>

More Information

More detailed notes on the usage of all the functions of LJS can be found in the API.

Owner

  • Name: Cory McCartan
  • Login: CoryMcCartan
  • Kind: user
  • Company: New York University

Faculty Fellow at NYU's Center for Data Science, working on computational social science problems and open-source R software.

GitHub Events

Total
Last Year

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 9
  • Total Committers: 1
  • Avg Commits per committer: 9.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Cory McCartan c****n@g****m 9

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Dependencies

bower.json bower
  • chai ^3.5.0 development
  • mocha ^2.4.5 development
package.json npm
  • documentation ^3.0.4 development