Skip to content

link-assistant/meta-expression

Repository files navigation

meta-expression

First prototype for a links-network based reasoning playground. It accepts a human-language statement, generates selectable interpretations, formalizes the selected meaning when possible, evaluates computable fragments, and attaches evidence with provenance for non-computable claims.

The implementation in this PR keeps the long-term direction documented in docs/REQUIREMENTS.md and docs/ROADMAP.md, while providing working library, CLI, microservice, and static web surfaces now.

The text-formalization and translation sub-systems have an auto-generated formalization reference at docs/FORMALIZE.md (regenerated from JSDoc with npm run docs:formalize).

Library

import { analyzeStatement, serializeLinksNotation } from './src/index.js';

const analysis = analyzeStatement('1 + 1 = 2');

console.log(analysis.result.value); // true
console.log(analysis.result.confidence); // 1
console.log(serializeLinksNotation(analysis.linksNetwork));

Core exports:

  • createStatementDraft(input) returns three interpretations and stops before formalization.
  • analyzeStatement(input, options) selects an interpretation and produces a links network, formalization, result, confidence, and evidence.
  • serializeLinksNotation(linksNetwork) exports the selected links network in a Lino-style text form.
  • getPreparedExamples() returns the current examples shown by the static web prototype.
  • describeFormalizationLevel(level) returns the level name, summary, and executability flag.
  • createIssueReportUrl(analysis, options) creates a prefilled GitHub issue URL with statement, result, evidence, and Links Notation.
  • createWikimediaEvidenceClient() and analyzeStatementWithLiveEvidence() resolve supported real-world claims through Wikimedia APIs with cacheable evidence.
  • formalizeTextWith(input, options) links phrases to Wikipedia, Wikidata, or fallback sources and returns Markdown, Links Notation, and a CST.
  • translateTextWith(input, options) formalizes first, then translates sentences through resolved Wikidata Q/P target-language labels and explicit transformation rules while preserving unresolved parts as variables with questions and trace steps.
  • checkText(input, options) detects statements in longer text, analyzes each statement, and returns red-to-green correctness coloring as JSON, HTML, Markdown, and Links Notation.
  • searchTextUniqueness(input, options) searches detected statements across public web and scholarly APIs, returning existing-likelihood scores, citation/rewording suggestions, source matches, HTML, Markdown, and Links Notation.

Current deterministic examples:

  • 1 + 1 = 2 -> computed true, confidence 1.
  • 1 + 1 = 1 -> computed false, confidence 0.
  • 1 + 1 -> arithmetic question result 2.
  • Earth orbits the Sun -> Wikidata-backed evidence estimate, confidence 0.99.
  • Moon orbits the Sun -> Wikidata-backed parent-body chain Moon -> Earth -> Sun, confidence 0.99.
  • Elon Musk is alive -> Wikidata-backed person-alive evidence estimate, confidence 0.99.
  • Paris is the capital of France -> live Wikimedia-capable country-capital evidence template.
  • this statement is false -> self-reference status undetermined, confidence 0.5.

Real-world confidence is intentionally bounded away from absolute 0% and 100%; exact certainty is reserved for deterministic computable expressions.

CLI

node src/cli.js analyze "1 + 1 = 2"
node src/cli.js analyze --input "Earth orbits the Sun" --format links
node src/cli.js analyze --input "Paris is the capital of France" --live
node src/cli.js formalize --input "Hawaii is a state." --format markdown
node src/cli.js translate --input "Hawaii is a state." --to ru --format markdown
node src/cli.js check --input "Earth orbits the Sun. 1 + 1 = 1." --format html
node src/cli.js fact-check --input "Paris is the capital of France." --live
node src/cli.js uniqueness --input "Earth orbits the Sun." --format markdown

Microservice

npm start
curl "http://127.0.0.1:3000/analyze?input=1%20%2B%201%20%3D%202"
curl "http://127.0.0.1:3000/analyze?input=Earth%20orbits%20the%20Sun&format=links"
curl "http://127.0.0.1:3000/translate?input=Hawaii%20is%20a%20state.&to=ru&format=markdown"
curl "http://127.0.0.1:3000/check?input=Earth%20orbits%20the%20Sun.%201%20%2B%201%20%3D%201.&format=html"
curl "http://127.0.0.1:3000/uniqueness?input=Earth%20orbits%20the%20Sun.&format=markdown"

Routes:

  • GET /health
  • GET /analyze?input=...&format=json|links&select=0
  • GET /analyze?input=...&live=true
  • POST /analyze with { "input": "...", "format": "json" }
  • GET /formalize?input=...&format=json|links|markdown|html
  • POST /formalize with { "input": "...", "format": "json" }
  • GET /translate?input=...&from=en&to=ru&format=json|links|markdown|html
  • POST /translate with { "input": "...", "targetLanguage": "ru" }
  • GET /check?input=...&format=json|links|markdown|html
  • POST /check with { "input": "...", "live": true }
  • GET /fact-check?input=... and POST /fact-check as aliases for /check
  • GET /uniqueness?input=...&format=json|links|markdown|html&limit=3
  • POST /uniqueness with { "input": "...", "limit": 3 }
  • GET /uniquness?input=... and POST /uniquness as compatibility aliases for the issue title typo.

Static Web Prototype

Serve the repository root and open web/index.html:

python3 -m http.server 4173

Then visit http://127.0.0.1:4173/web/.

On main, CI publishes the same static prototype to the repository's GitHub Pages /web/ path after tests pass.

The web prototype includes prepared examples, an interpretation selector, local belief slider saved in localStorage, two default metrics (Correctness and signed Confidence), result/evidence summaries, Q/P source links in the links network, Links Notation output, a live Wikimedia evidence worker, a global prefilled GitHub issue report link with page state and deployed version metadata, and a top-menu page switch between Analyse (default), Compare, Check, Uniqueness, Formalize, Translate, and Preferences. The Check page colors each detected statement from red (wrong) to green (correct) and exposes the checked result as Markdown and Links Notation. The Uniqueness page searches public APIs for prior instances of each detected statement and suggests citing, quoting, reviewing, or rewording statements that look already published. The Translate page uses the formalization CST to show formalized source text, translated sentence output, unresolved questions, Markdown, Links Notation, the translation CST, and a collapsed step trace. The Preferences page stores a local profile with worldview sliders, context presets, and Links Notation import/export.

Default metrics

Every analysis surfaces two complementary numbers (see docs/case-studies/issue-13/analysis.md):

  • Correctness (result.correctness, 0% … 100%) — how correct the claim is in absolute terms. 100% means perfectly correct, 0% means perfectly wrong.
  • Confidence (result.signedConfidence, -100% … +100%) — net evidential weight; positive points toward truth, negative points toward the negation, zero is indecisive. Useful for ranking competing claims about the same subject (e.g. Population of Russia is 100m vs Population of Russia is 200m).

The two are linked by signedConfidence ≈ 2 · correctness − 1. The legacy result.confidence (0..1) and result.rawBalance (-1..1) properties are preserved unchanged for backwards compatibility.

Rust Core

The Rust workspace under rust/core contains WASM-ready core primitives and uses the doublets crate for relation-link doublet encoding:

cargo test --workspace

Development

npm install
npm test
npm run check
scripts/check-file-line-limits.sh

The package keeps the existing multi-runtime test setup based on test-anywhere, so tests should also pass under Bun and Deno in CI.

About

An expression about expression

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors