eyemind 0.7.2 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@ eyemind is a dependency-free reasoner for **Logic Script (LS)**, a rule language
7
7
 
8
8
  [Playground](https://eyereasoner.github.io/eyemind/playground/) · [Specification](https://eyereasoner.github.io/eyemind/SPEC) · [Conformance](https://eyereasoner.github.io/eyemind/conformance/) · [Examples](https://eyereasoner.github.io/eyemind/examples/)
9
9
 
10
- The playground runs programs in your browser; the specification defines the language, its canonical text, the proof format and how a proof is checked. The examples are 147 runnable programs, each with a card deck and saved conclusions, proofs and check reports. The conformance suite has 1246 cases that test language and proof behavior through a command adapter, together with implementation interface checks; run it [in your browser](https://eyereasoner.github.io/eyemind/playground/conformance).
10
+ The playground runs programs in your browser; the specification defines the language, its canonical text, the proof format and how a proof is checked. The examples are 152 runnable programs, each with a card deck and saved conclusions, proofs and check reports. The conformance suite has 1246 cases that test language and proof behavior through a command adapter, together with implementation interface checks; run it [in your browser](https://eyereasoner.github.io/eyemind/playground/conformance).
11
11
 
12
12
  ## Contents
13
13
 
@@ -24,6 +24,10 @@ The playground runs programs in your browser; the specification defines the lang
24
24
  - [RDF Messages](#rdf-messages)
25
25
  - [SPARQL 1.2 RL](#sparql-12-rl)
26
26
  - [OWL 2 RL](#owl-2-rl)
27
+ - [Combining RDF logic profiles](#combining-rdf-logic-profiles)
28
+ - [QUDT quantities](#qudt-quantities)
29
+ - [SKOS entailment](#skos-entailment)
30
+ - [SHACL validation](#shacl-validation)
27
31
  - [ODRL snapshots](#odrl-snapshots)
28
32
  - [How eyemind reasons](#how-eyemind-reasons)
29
33
  - [Proofs, and what checking one means](#proofs-and-what-checking-one-means)
@@ -467,16 +471,23 @@ The implemented rules are:
467
471
  | RDFS | Class and property hierarchy transitivity, type and property propagation, domain and range inference and inheritance, resource/class/property typing, reflexive hierarchies, container membership and datatype-to-literal subclassing. |
468
472
  | OWL | Equality and substitution; equivalent classes and properties; inverse, symmetric, transitive, functional and inverse-functional properties; property chains and keys; intersections, unions, enumerations, value restrictions and maximum cardinalities 0 and 1; class/property disjointness, AllDifferent, negative property assertions and schema propagation. |
469
473
 
470
- The OWL rules implement the non-datatype rule families of
474
+ The OWL rules cover the non-datatype families of
471
475
  [OWL 2 RL/RDF tables 4–7 and 9](https://www.w3.org/TR/owl2-profiles/#Reasoning_in_OWL_2_RL_and_RDF_Graphs),
472
- inspired by [EYE's RDF plus OWL rules](https://github.com/eyereasoner/eye/tree/master/reasoning/rpo).
473
- They operate on the terms present in each graph. RDFS axiomatic triples,
474
- datatype value-space reasoning (OWL table 8), ontology imports and OWL
475
- constructs outside these rule families are not implemented. Literal equality
476
- uses the RDF-to-LS representation, without general datatype normalization.
477
- This switch does not validate profile membership or certify completeness
478
- for arbitrary RDFS or OWL ontologies. It takes RDF inputs and cannot be combined
479
- with `--odrl` or `--stream-messages`.
476
+ inspired by [EYE's RDF plus OWL rules](https://github.com/eyereasoner/eye/tree/master/reasoning/rpo)
477
+ and the [rdfjs-inference-engine rule sets](https://github.com/pietercolpaert/rdfjs-inference-engine/tree/main/rules).
478
+ Disjoint lists also infer pairwise differences or disjointness, and reflexive
479
+ properties apply to resources present in the graph.
480
+
481
+ Datatype reasoning is partial: integer and decimal comparisons are exact,
482
+ integer subtype bounds are checked, and boolean and string values are
483
+ compared across supported lexical spellings. Supported datatype IRIs present
484
+ in a graph are recognized as datatypes. Maximum qualified cardinalities can
485
+ use `owl:onDataRange`. This does not implement all of OWL table 8: full
486
+ datatype inclusion/disjointness, facets, binary floating-point value equality
487
+ and temporal value equality are outside the profile. RDFS axiomatic triples,
488
+ ontology imports and constructs beyond these rule families are also outside
489
+ it. The switch does not validate OWL profile membership or certify
490
+ completeness for arbitrary ontologies.
480
491
 
481
492
  OWL contradictions appear as RDF records of type `ent:Conflict`, where
482
493
  `ent:` is `https://eyereasoner.github.io/eyemind/entailment#`. Each records its
@@ -489,7 +500,184 @@ guarantee. RDFS domain and range infer types rather than checking required
489
500
  fields, and missing facts alone do not establish a conflict.
490
501
 
491
502
  Try the [people directory](https://eyereasoner.github.io/eyemind/examples/deck/people-owl2rl)
492
- and [family ontology](https://eyereasoner.github.io/eyemind/examples/deck/family-owl2rl).
503
+ [family ontology](https://eyereasoner.github.io/eyemind/examples/deck/family-owl2rl)
504
+ and [datatype catalog](https://eyereasoner.github.io/eyemind/examples/deck/datatypes-owl2rl).
505
+
506
+ ### Combining RDF logic profiles
507
+
508
+ `--owl2rl`, `--qudt`, `--skos` and `--shacl` can be combined. Each explicitly
509
+ adds its logic to RDF inputs; vocabulary alone never enables a profile.
510
+ Multiple inputs merge their default graphs. Named graphs remain independent:
511
+ put each graph's data and shapes together, and use `--to trig` to retain graph
512
+ names in the output. These switches cannot be combined with `--odrl` or
513
+ `--stream-messages`.
514
+
515
+ All four compile to standalone `.js` containing the data and ordinary LS
516
+ rules. Inference closes before validation, whose reports cannot affect
517
+ inference. Output defaults to Turtle containing new triples and reports;
518
+ `--all` includes the input. Proofs and check reports remain `.js`, including
519
+ proofs of validation failures. Exit code 0 means evaluation completed;
520
+ inspect `sh:conforms` and any `ent:Conflict` records to assess the graph.
521
+ The playground exposes the same switches and preserves combinations in
522
+ saved sessions and shared links.
523
+
524
+ ```sh
525
+ eyemind --qudt --shacl examples/measurement-shacl.ttl
526
+ eyemind --qudt --shacl --program examples/measurement-shacl.ttl > /tmp/measurement.js
527
+ eyemind --to turtle /tmp/measurement.js
528
+ eyemind --qudt --shacl --proof examples/measurement-shacl.ttl > /tmp/measurement-proof.js
529
+ eyemind --qudt --shacl --check-proof /tmp/measurement-proof.js examples/measurement-shacl.ttl
530
+ ```
531
+
532
+ ### QUDT quantities
533
+
534
+ `--qudt` normalizes linked `qudt:QuantityValue` objects and quantity literals
535
+ using current `https://w3id.org/cdt/` or legacy
536
+ `http://w3id.org/lindt/custom_datatypes#` datatypes. For example,
537
+ `"36 km/h"^^cdt:speed` yields `"10.0 m/s"^^cdt:speed`. The object form needs
538
+ an incoming `subject property quantity` link, a `qudt:QuantityValue` type,
539
+ `qudt:numericValue` and `qudt:unit`. Only input measurements are normalized;
540
+ generated quantities do not create another generation of measurements.
541
+
542
+ The offline catalog contains common length, area, volume, time, mass, speed,
543
+ acceleration, temperature, pressure, energy, power, dimensionless, electric
544
+ current and amount-of-substance units. Defaults are SI units. Unit tokens
545
+ include registered symbols and UCUM spellings; this is a finite catalog,
546
+ not a general UCUM expression parser or the complete QUDT ontology.
547
+ Affine conversion uses `(value + offset) * multiplier`, including Fahrenheit.
548
+ Selected logarithmic conventions are power-ratio bel/decibel, neper,
549
+ octave, decade and pH. Conversions use binary64 arithmetic; logarithmic
550
+ results can depend on the host math library's last-place rounding.
551
+
552
+ Input unit metadata extends or overrides the catalog with
553
+ `qudt:hasDimensionVector`, `qudt:conversionMultiplier`, optional
554
+ `qudt:conversionOffset` (zero by default), and `qudt:symbol`, `qudt:ucumCode`
555
+ or `qudt:expression` tokens. A custom affine definition needs both its
556
+ dimension vector and multiplier. Local unit IRIs can align to a known unit
557
+ through `owl:sameAs`, `skos:exactMatch` or `qconv:alignedQudtUnit`; enabling
558
+ OWL or SKOS also supplies their inferred alignments.
559
+
560
+ Here `qconv:` is `https://eyereasoner.github.io/eyemind/qudt#`. A property
561
+ can select a `qconv:normalizationProfile`; built-in profiles include
562
+ `qconv:LengthProfile`, `qconv:SpeedProfile` and `qconv:TemperatureProfile`.
563
+ A custom profile supplies `qconv:targetUnit`, `qconv:datatype` (an IRI) and
564
+ `qconv:targetUcumCode` (a string). Generic `cdt:ucum` literals and quantity
565
+ objects otherwise select an unambiguous profile by dimension. Specific CDT
566
+ literals select their datatype's profile and must agree with any property
567
+ contract. Source and target dimension vectors must match. Unknown tokens,
568
+ incompatible dimensions, ambiguous profiles and unsupported conversions
569
+ produce no normalization; use SHACL required-value constraints when missing
570
+ normalization must be reported.
571
+
572
+ Each result attaches `qconv:normalizedQuantity`,
573
+ `qconv:normalizedUcumLiteral` and `qconv:normalizedCdtLiteral` to the original
574
+ subject. The generated quantity records its unit and numeric value, plus
575
+ `qconv:sourceProperty`, `qconv:sourceUnit` and `qconv:sourceLiteral` or
576
+ `qconv:sourceQuantity`. Legacy literals normalize to current CDT datatypes.
577
+ The small catalog is adapted from [QUDT.org](https://qudt.org/), licensed
578
+ [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), and can be inspected
579
+ in `src/qudt.js`. No ontology is downloaded during compilation.
580
+ Try [quantities](https://eyereasoner.github.io/eyemind/examples/deck/quantities-qudt).
581
+
582
+ ### SKOS entailment
583
+
584
+ `--skos` adds positive [SKOS Core entailments](https://www.w3.org/TR/skos-reference/):
585
+ concept and scheme typing, labels and notes, top concepts, hierarchical and
586
+ associative relations, mapping relations and ordered collection membership.
587
+ `skos:broader` and `skos:closeMatch` are not transitive;
588
+ `skos:broaderTransitive`, `skos:narrowerTransitive` and `skos:exactMatch` are.
589
+ A collection member is not arbitrarily typed as either a concept or a
590
+ collection, and related concepts do not acquire a shared scheme without
591
+ supporting assertions. Cyclic lists do not invent collection members.
592
+
593
+ The profile emits its vocabulary axioms and resulting triples. It does not
594
+ check SKOS integrity conditions or implement SKOS-XL. Add `--owl2rl` for
595
+ general RDFS/OWL consequences of the vocabulary.
596
+ Try the [transport thesaurus](https://eyereasoner.github.io/eyemind/examples/deck/thesaurus-skos).
597
+
598
+ ### SHACL validation
599
+
600
+ `--shacl` compiles the supplied shapes into LS predicates with explicit
601
+ conformance dependencies. Validation inspects the completed graph, including
602
+ consequences from the other selected profiles. It writes a standard
603
+ `sh:ValidationReport` with `sh:conforms` and linked `sh:ValidationResult`
604
+ records carrying focus node, source shape, constraint component and severity,
605
+ plus path, value and supplied messages where applicable. Complex result
606
+ paths retain their RDF definitions in the report.
607
+
608
+ SHACL 1.2 Core is implemented: node, class, subjects-of, objects-of and where
609
+ targets, `sh:shape` links in the data, and implicit class targets including
610
+ `sh:ShapeClass`; class, datatype, node-kind and root-class constraints, each
611
+ also with a list of alternatives; counts, bounds, lengths, patterns, single
612
+ lines and language constraints; SHACL list members, lengths and uniqueness;
613
+ sets, unique values for targets, property pairs over any path, and closed
614
+ shapes, also `sh:ByTypes`; nested properties, node/not/and/or/xone,
615
+ `sh:someValue`, reifier shapes and qualified counts with disjoint siblings.
616
+ Constant `sh:values` and `sh:defaultValue` add value nodes. Predicate,
617
+ inverse, sequence, alternative and repeated paths compute distinct values and
618
+ terminate on data cycles. Repeated `xone` members count separately.
619
+
620
+ A reifier of a constraint triple can deactivate that constraint or give it its
621
+ own `sh:severity` and `sh:message`. Each validation of a focus node is a
622
+ separate result, so a nested shape reached by two routes reports twice, and
623
+ `sh:lessThan` reports each incomparable pair. Results whose severity is outside
624
+ the conformance-disallow set (`sh:Violation`, `sh:Warning` and `sh:Info` by
625
+ default) are reported but do not make a node or the report nonconforming; a
626
+ library caller can pass another set as `disallows`, which the report then
627
+ lists as `sh:conformanceDisallows`. Only the boolean `true` activates a
628
+ boolean parameter. Deactivated shapes conform without validation.
629
+
630
+ Shapes and path definitions must be present in the input; inference may add
631
+ data and targets, but cannot dynamically define new constraints. Recursive
632
+ shape dependencies, node expressions beyond constants, SHACL-SPARQL,
633
+ JavaScript constraints and rules are outside the implementation. Active
634
+ shapes with unsupported constraint predicates are rejected.
635
+
636
+ Datatype checks support XSD integer subtypes, decimal, float/double, boolean,
637
+ string/normalizedString/token/language/anyURI, hex/base64 binary,
638
+ date/dateTime/dateTimeStamp/time and RDF language strings; a literal of
639
+ another datatype matches that datatype's IRI. Numeric bounds use exact integers/decimals with
640
+ SPARQL promotion for binary floats; string and same-kind temporal bounds
641
+ are also supported. Temporal fractions remain exact. Timezones compare
642
+ when both values have one or both omit one; a mixed pair is incomparable.
643
+ Unsupported comparisons fail their constraint.
644
+
645
+ Patterns use the LS Unicode ECMAScript regex primitive. Flag `s` and the
646
+ whitespace-removing flag `x` are translated; `i` supports ASCII literal and
647
+ character-class folding. Flag `m`, non-ASCII case folding and richer escaped
648
+ case-insensitive patterns raise errors. XPath-specific regex syntax is not
649
+ implemented. Malformed shapes and unsupported features produce specific
650
+ errors instead of a conforming report.
651
+ Try the [directory](https://eyereasoner.github.io/eyemind/examples/deck/people-shacl)
652
+ and [normalized speed readings](https://eyereasoner.github.io/eyemind/examples/deck/measurement-shacl).
653
+
654
+ The [W3C SHACL 1.2 manifest](https://w3c.github.io/data-shapes/shacl12-test-suite/tests/manifest.ttl)
655
+ is scored on every `npm test`, including filtered runs. eyemind targets its
656
+ Core and node-expression groups; SHACL-SPARQL and inference rules are out of
657
+ scope and not scored. At upstream revision
658
+ `0ed3f9b4273c2debba0125a7ed5c9dc3cd4b741c`, **all 162 Core tests pass
659
+ complete-report comparison**. Node expressions beyond constants are not yet
660
+ implemented, so the 284 node-expression tests do not pass yet.
661
+
662
+ The two groups are reported separately in
663
+ [REPORT.md](REPORT.md) and [SHACL EARL](reports/w3c-shacl-earl.ttl). The runner
664
+ preserves separate data and shapes graphs, follows manifest includes and
665
+ compares complete top-level results, their multiplicity, messages and paths.
666
+ A matching conformance boolean alone is not a pass. Unimplemented processor
667
+ families are explicitly untested in EARL; attempted validation cases that
668
+ reject unsupported constraints or produce wrong reports are failed.
669
+
670
+ ```sh
671
+ node tools/shacltests.js
672
+ node tools/shacltests.js --json > /tmp/shacl-coverage.json
673
+ node tools/shacltests.js --strict
674
+ ```
675
+
676
+ The default scorer and `npm test` report SHACL coverage without making missing
677
+ support fail the release checks, as with the Notation3 scorer. `--strict` exits
678
+ with code 1 for any non-passing SHACL case. Broken manifests and missing test
679
+ resources always fail the run. These commands reuse the cached suite; an
680
+ optional suite directory can select a different copy.
493
681
 
494
682
  ### ODRL snapshots
495
683
 
@@ -729,12 +917,15 @@ eyemind [OPTION ...] [FILE ...]
729
917
  | `--unused` | List the clauses that make no difference to the conclusions. |
730
918
  | `--stream-messages` | Read an RDF Message Log and run the rules independently per message; Node reads files, stdin and HTTP(S) incrementally. |
731
919
  | `--stats` | Print reasoning statistics as JSON to standard error. |
732
- | `--max-depth N`, `--max-iterations N`, `--max-inferences N` | Bound backward depth (1000000), forward rounds per stratum (1000) and goals started (1000000); a compiled N3, SRL, ODRL, RDFS or OWL 2 RL program has 1000000, 100000 and 1000000000. |
733
- | `--to FORMAT` | Write the conclusions as `turtle`, `trig`, `n-triples`, `n-quads`, `n3`, `le` or `eyemind`; by default LE for LE, N3 for N3, Turtle for SRL, ODRL, RDFS and OWL 2 RL, eyemind otherwise. |
920
+ | `--max-depth N`, `--max-iterations N`, `--max-inferences N` | Bound backward depth (1000000), forward rounds per stratum (1000) and goals started (1000000); a compiled N3, SRL, ODRL or RDF profile program has 1000000, 100000 and 1000000000. |
921
+ | `--to FORMAT` | Write the conclusions as `turtle`, `trig`, `n-triples`, `n-quads`, `n3`, `le` or `eyemind`; by default LE for LE, N3 for N3, Turtle for SRL, ODRL and RDF profiles, eyemind otherwise. |
734
922
  | `--all` | With RDF or N3 output, write the given data too. |
735
923
  | `--program` | Print the program the inputs compile to. |
736
924
  | `--odrl` | Add the ODRL snapshot profile's validation and evaluation LS to one Turtle input. |
737
925
  | `--owl2rl` | Add the documented OWL 2 RL inference rules, including RDFS, and RDF conflict reports to RDF inputs. |
926
+ | `--qudt` | Normalize supported QUDT/CDT quantities, with source provenance. |
927
+ | `--skos` | Add positive SKOS Core entailments. |
928
+ | `--shacl` | Compile supported SHACL Core shapes to LS and output RDF validation reports. |
738
929
  | `--base IRI` | Resolve relative IRIs of the inputs against `IRI` instead of each file's location. |
739
930
  | `-v`, `--version`, `-h`, `--help` | Print the version or the usage. |
740
931
 
@@ -744,7 +935,7 @@ each goal as a data document, with an array denoting conjunction. With
744
935
  `--check-proof`, supply the original goals the proof answers.
745
936
  An option that takes a value requires it immediately afterward; another
746
937
  option, including a short alias such as `-v`, is reported as a missing value.
747
- With `--goal`, answers default to eyemind terms even for LE, N3, SRL, ODRL, RDFS and OWL 2 RL inputs;
938
+ With `--goal`, answers default to eyemind terms even for LE, N3, SRL, ODRL and RDF profile inputs;
748
939
  use `--to` to request another output format.
749
940
 
750
941
  With `--prove-and-check`, reasoning bounds and `--stats` apply to proof
@@ -773,7 +964,7 @@ They are outside the language and proof specification.
773
964
 
774
965
  The JavaScript implementation defaults to a depth limit of 1000000, an
775
966
  inference limit of 1000000 and a limit of 1000 forward rounds per stratum.
776
- Compiled N3, SRL, ODRL and OWL 2 RL programs use 1000000, 1000000000 and 100000 respectively.
967
+ Compiled N3, SRL, ODRL and RDF profile programs use 1000000, 1000000000 and 100000 respectively.
777
968
  Each supplied bound must be a positive integer no greater than
778
969
  9007199254740991.
779
970
 
@@ -864,7 +1055,8 @@ EYEMIND_PROPERTY_SCALE=20 npm test -- -k properties # deeper generated tests
864
1055
  node tools/update-examples.js # regenerate example artifacts after an intended change
865
1056
  node tools/report.js # run the full suite and write REPORT.md
866
1057
  node tools/notation3tests.js # the cached Notation3 suite
867
- npm run sync # refresh all three upstream test suites
1058
+ node tools/shacltests.js # SHACL 1.2 coverage; --strict fails for missing support
1059
+ npm run sync # refresh all four upstream test suites
868
1060
  node conformance/run.js --command "my-eyemind" # run the conformance suite against another implementation
869
1061
  ```
870
1062
 
@@ -874,16 +1066,18 @@ A full `npm test` writes `REPORT.md` from the summary table it prints.
874
1066
 
875
1067
  Every `npm test` invocation, including a filtered run, also runs both cached
876
1068
  W3C format suites and rewrites [reports/w3c-rdf-earl.ttl](reports/w3c-rdf-earl.ttl)
877
- and [reports/w3c-sparql-rl-earl.ttl](reports/w3c-sparql-rl-earl.ttl).
1069
+ and [reports/w3c-sparql-rl-earl.ttl](reports/w3c-sparql-rl-earl.ttl). It also scores
1070
+ the Core and node-expression groups of the SHACL 1.2 manifest and writes
1071
+ [reports/w3c-shacl-earl.ttl](reports/w3c-shacl-earl.ttl).
878
1072
  These [EARL](https://www.w3.org/TR/EARL10-Schema/) reports contain one
879
1073
  assertion per manifest case, its actual outcome and diagnostic, the eyemind
880
- version and the run date. A W3C failure makes the command fail. A negative
1074
+ version and the run date. An RDF or SRL failure makes the command fail; SHACL is reported as coverage. A negative
881
1075
  syntax test passes when the parser rejects its input as required.
882
1076
 
883
1077
  The [upstream suites](test/UPSTREAM.md) live in Git-ignored `.cache/`.
884
1078
  `npm test` reuses them without fetching. If the cache is missing or incomplete,
885
1079
  it downloads the suites first; that first run needs Git and network access.
886
- `npm run sync` explicitly refreshes all three suites and the Notation3 document
1080
+ `npm run sync` explicitly refreshes all four suites and the Notation3 document
887
1081
  fixtures. Downloads and manifest resource checks finish before the cached
888
1082
  suites are replaced; a failed refresh retains the old set. Upstream licensing
889
1083
  and documentation stay with the cached files. The small tracked
@@ -896,6 +1090,9 @@ Local Git checkouts can supply any of the sources:
896
1090
  npm run sync -- --notation3tests /path/to/notation3tests --w3c-rdf /path/to/rdf-tests --w3c-sparql-rl /path/to/data-shapes
897
1091
  ```
898
1092
 
1093
+ The data-shapes checkout supplies both SRL and SHACL; `--w3c-shacl PATH` can
1094
+ select a separate checkout for SHACL.
1095
+
899
1096
  `node tools/sync-notation3tests.js [UPSTREAM_CHECKOUT]` still refreshes only
900
1097
  Notation3 in `.cache/`. Once cached, tests use saved documents with no network fallback;
901
1098
  the scorer's `--live` option checks the current remote resources instead.
package/SPEC.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ```text
4
4
  Title: The Logic Script (LS) Language and Proof Format
5
- Version: eyemind 0.7.2
5
+ Version: eyemind 0.8.1
6
6
  ```
7
7
 
8
8
  This document specifies Logic Script (LS): the syntax and meaning of its
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyemind",
3
- "version": "0.7.2",
3
+ "version": "0.8.1",
4
4
  "description": "A dependency-free Logic Script (LS) reasoner with forward and backward reasoning, checkable proofs, and RDF 1.2, Notation3 (N3) and SPARQL 1.2 RL (SRL) interoperability.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // The eyemind command line.
2
2
  import { run, unusedClauses } from './engine.js';
3
- import { OUTPUT_FORMATS, defaultFormat, inputKind, loadInputs, rdfMessageFormat, scopeOf, writeConclusions } from './formats.js';
3
+ import { OUTPUT_FORMATS, RDF_PROFILES, defaultFormat, inputKind, loadInputs, rdfMessageFormat, scopeOf, writeConclusions } from './formats.js';
4
4
  import { isRdfMessageLog, replayMessages, RdfMessageReader } from './messages.js';
5
5
  import { checkProof, checkReport, publicReport } from './proof.js';
6
6
  import { EyemindError } from './terms.js';
@@ -25,11 +25,14 @@ all compiled to LS.
25
25
  --max-inferences N Bound reasoning work (default 1000000)
26
26
  --to FORMAT Write the conclusions as turtle, trig, n-triples,
27
27
  n-quads, n3, le or eyemind (default: le for LE, n3 for N3, turtle
28
- for SRL, ODRL or OWL 2 RL, eyemind otherwise or with --goal)
28
+ for SRL, ODRL or RDF logic profiles, eyemind otherwise or with --goal)
29
29
  --all With RDF or N3 output, write the given data too
30
30
  --program Print the program the inputs compile to
31
31
  --odrl Add ODRL validation and evaluation to one Turtle snapshot
32
32
  --owl2rl Add OWL 2 RL inference, including RDFS, and conflict rules
33
+ --qudt Normalize QUDT quantities and CDT unit literals
34
+ --skos Add positive SKOS Core entailments
35
+ --shacl Compile SHACL Core shapes into LS validation rules
33
36
  --base IRI Resolve relative IRIs of the inputs against IRI
34
37
  --stream-messages Run the rules independently for each RDF Message
35
38
  -v, --version Print the version
@@ -69,7 +72,7 @@ export function main(argv, io) {
69
72
  let base = null;
70
73
  let streamMessages = false;
71
74
  let odrl = false;
72
- let owl2rl = false;
75
+ const rdfLogic = {};
73
76
  const filePositions = new Set();
74
77
  for (let i = 0; i < argv.length; i++) {
75
78
  const arg = ALIASES.get(argv[i]) ?? argv[i];
@@ -97,8 +100,8 @@ export function main(argv, io) {
97
100
  printProgram = true;
98
101
  } else if (arg === '--odrl') {
99
102
  odrl = true;
100
- } else if (arg === '--owl2rl') {
101
- owl2rl = true;
103
+ } else if (arg.startsWith('--') && RDF_PROFILES.includes(arg.slice(2))) {
104
+ rdfLogic[arg.slice(2)] = true;
102
105
  } else if (arg === '--stream-messages') {
103
106
  streamMessages = true;
104
107
  } else if (arg === '--check-proof' || arg === '--goal' || arg === '--to' || arg === '--base' || Object.hasOwn(LIMITS, arg)) {
@@ -147,7 +150,7 @@ export function main(argv, io) {
147
150
  if (files.filter((file) => file === '-').length > 1) throw new UsageError('stdin can only be read once');
148
151
  if (streamMessages) {
149
152
  if (odrl) throw new UsageError('--odrl cannot be combined with --stream-messages');
150
- if (owl2rl) throw new UsageError('--owl2rl cannot be combined with --stream-messages');
153
+ if (Object.keys(rdfLogic).length) throw new UsageError(`${Object.keys(rdfLogic).map((p) => '--' + p).join(' ')} cannot be combined with --stream-messages`);
151
154
  if (proofFile !== null || options.proof || proveAndCheck || printProgram || unused) {
152
155
  throw new UsageError('--stream-messages cannot be combined with --proof, --check-proof, --prove-and-check, --program or --unused; replay the whole log to prove its conclusions');
153
156
  }
@@ -188,7 +191,7 @@ export function main(argv, io) {
188
191
  }
189
192
  const document = proofFile === null ? null : readSource(proofFile, io);
190
193
  const loaded = loadInputs(files.map((file) => [readSource(file, io), file === '-' ? '<stdin>' : file]), io,
191
- { base, messageInputs: io.messageInputs, odrl, owl2rl,
194
+ { base, messageInputs: io.messageInputs, odrl, ...rdfLogic,
192
195
  srlContext: document !== null && files.some((file) => inputKind(file) === 'srl') ? srlContextFromProof(document) : null });
193
196
  const program = loaded.program;
194
197
  if (printProgram) {
package/src/formats.js CHANGED
@@ -14,7 +14,7 @@
14
14
  //
15
15
  // The odrl option adds the snapshot profile's validation and evaluation LS
16
16
  // to one Turtle input. Its vocabulary alone never enables the evaluator.
17
- // owl2rl adds OWL 2 RL rules, including RDFS, to RDF inputs.
17
+ // Explicit owl2rl, qudt, skos and shacl profiles share one RDF working graph.
18
18
  //
19
19
  // The compiled program is ordinary LS: proofs, checking and --unused
20
20
  // apply to it. SRL execution functions capture a context that a saved proof
@@ -26,12 +26,13 @@ import { DEFAULT_GRAPH, parseRdf, rdfDocument, rdfFormat, writeRdf } from './rdf
26
26
  import { resultToN3, compileSources } from './n3.js';
27
27
  import { compileSrl, srlAnswers, srlQuads } from './srl.js';
28
28
  import { compileOdrl } from './odrl.js';
29
- import { compileOwl2rl } from './owl2rl.js';
29
+ import { compileRdfLogic, RDF_PROFILES } from './rdf-logic.js';
30
30
  import { compileLe, writeLe } from './le.js';
31
31
  import { write } from './writer.js';
32
32
  import { isRdfMessageLog, parseRdfMessages } from './messages.js';
33
33
 
34
34
  export const OUTPUT_FORMATS = ['eyemind', 'turtle', 'trig', 'n-triples', 'n-quads', 'n3', 'le'];
35
+ export { RDF_PROFILES };
35
36
 
36
37
  // What a file holds: 'js', 'rdf', 'n3', 'srl' or 'le'.
37
38
  export function inputKind(name) {
@@ -50,7 +51,7 @@ export function rdfMessageFormat(name) {
50
51
  // Load inputs, given as [text, name] pairs, as one program. io may supply
51
52
  // readFile, for the documents N3 and IMPORTS name, and fileIri(name), the
52
53
  // base IRI of a file. Returns { kind, program, text, prefixes, compiled }:
53
- // kind is 'js', 'n3', 'srl', 'le', 'odrl' or 'owl2rl', text the compiled program,
54
+ // kind is 'js', 'n3', 'srl', 'le', 'odrl' or an RDF profile name; text is the program,
54
55
  // and compiled what writing the conclusions needs.
55
56
  export function loadInputs(inputs, io = null, options = {}) {
56
57
  try {
@@ -62,7 +63,9 @@ export function loadInputs(inputs, io = null, options = {}) {
62
63
  }
63
64
  }
64
65
 
65
- function load(inputs, io, { base = null, messageInputs = null, srlContext = null, odrl = false, owl2rl = false }) {
66
+ function load(inputs, io, { base = null, messageInputs = null, srlContext = null, odrl = false, owl2rl = false, qudt = false, skos = false, shacl = false }) {
67
+ const options = { owl2rl, qudt, skos, shacl }, profiles = RDF_PROFILES.filter((p) => options[p]);
68
+ const switches = profiles.map((p) => '--' + p).join(' ');
66
69
  const kinds = inputs.map(([text, name]) => messageInputs?.has(name) ||
67
70
  (inputKind(name) === 'n3' && isRdfMessageLog(text)) ? 'rdf' : inputKind(name));
68
71
  const baseOf = (name) => base ?? io?.fileIri?.(name) ?? null;
@@ -72,24 +75,24 @@ function load(inputs, io, { base = null, messageInputs = null, srlContext = null
72
75
  });
73
76
  // These rule sets are added only when requested, never from vocabulary.
74
77
  if (kinds.includes('le')) {
75
- if (kinds.some((kind) => kind !== 'le') || odrl || owl2rl) {
78
+ if (kinds.some((kind) => kind !== 'le') || odrl || profiles.length) {
76
79
  throw new EyemindError('a Logical English run takes .le files without RDF logic switches or other input formats');
77
80
  }
78
81
  return compileLe(inputs);
79
82
  }
80
- if (owl2rl && odrl) throw new EyemindError('--odrl cannot be combined with --owl2rl');
81
- if (owl2rl) {
83
+ if (profiles.length && odrl) throw new EyemindError(`--odrl cannot be combined with ${switches}`);
84
+ if (profiles.length) {
82
85
  if (inputs.some(([, name], k) => kinds[k] !== 'rdf' && name !== '<stdin>')) {
83
- throw new EyemindError('--owl2rl takes RDF inputs; standard input is Turtle');
86
+ throw new EyemindError(`${switches} takes RDF inputs; standard input is Turtle`);
84
87
  }
85
88
  const prefixes = {}, quads = [];
86
89
  inputs.forEach(([text, name], k) => {
87
90
  const parsed = name === '<stdin>' ? parseRdf(text, { format: 'turtle', base: baseOf(name), scope: scopeOf(inputs, name, k) }) : rdf(text, name, k);
88
- if (parsed.triples) throw new EyemindError('--owl2rl takes RDF graphs, not RDF Message Logs');
91
+ if (parsed.triples) throw new EyemindError(`${switches} takes RDF graphs, not RDF Message Logs`);
89
92
  Object.assign(prefixes, parsed.prefixes);
90
93
  quads.push(...parsed.quads);
91
94
  });
92
- return compileOwl2rl({ quads, prefixes }, { source: inputs.map(([, n]) => n).join(', ') });
95
+ return compileRdfLogic({ quads, prefixes }, { profiles, source: inputs.map(([, n]) => n).join(', ') });
93
96
  }
94
97
  if (odrl) {
95
98
  if (inputs.length !== 1) throw new EyemindError('--odrl takes one Turtle snapshot containing policies, requests and SOTW');
@@ -155,7 +158,7 @@ function importResolver(io) {
155
158
 
156
159
  // Default output: LE for LE, N3 for N3, Turtle for SRL and the RDF logic
157
160
  // extensions, and eyemind's own text for an LS program.
158
- export const defaultFormat = (kind) => ({ le: 'le', n3: 'n3', srl: 'turtle', odrl: 'turtle', owl2rl: 'turtle' })[kind] ?? 'eyemind';
161
+ export const defaultFormat = (kind) => RDF_PROFILES.includes(kind) ? 'turtle' : ({ le: 'le', n3: 'n3', srl: 'turtle', odrl: 'turtle' })[kind] ?? 'eyemind';
159
162
 
160
163
  // The conclusions of a run in an output format; null for eyemind's own text.
161
164
  // all also writes given RDF or N3 data. Rejects conclusions the format cannot represent.
package/src/owl2rl.js CHANGED
@@ -1,19 +1,7 @@
1
1
  // OWL 2 RL inference, including RDFS, compiled to standalone Logic Script.
2
2
  // Rule names follow W3C OWL 2 RL/RDF tables 4–7 and 9:
3
3
  // https://www.w3.org/TR/owl2-profiles/#Reasoning_in_OWL_2_RL_and_RDF_Graphs
4
- import { loadText } from './lang.js';
5
- import { rdfDocument } from './rdf.js';
6
-
7
- export const ENTAILMENT = 'https://eyereasoner.github.io/eyemind/entailment#';
8
-
9
- export function compileOwl2rl({ quads, prefixes }, { source = '<input>' } = {}) {
10
- const text = `// Generated by eyemind from ${String(source).replace(/[\r\n\u2028\u2029]/g, ' ')}, with --owl2rl.\n` +
11
- '// rdf(S, P, O, G) is the working graph; result_rdf contains new RDF conclusions.\n' +
12
- `facts_from({ text: ${JSON.stringify(rdfDocument(quads))} })\n` +
13
- `facts_from({ text: ${JSON.stringify(rdfDocument(quads, 'ent_base'))} })\n` +
14
- COMMON + RDFS + OWL + OUTPUT;
15
- return { kind: 'owl2rl', text, program: loadText(text, source), prefixes: { ...prefixes, ent: ENTAILMENT }, compiled: null };
16
- }
4
+ // The common graph and reporting clauses are supplied by rdf-logic.js.
17
5
 
18
6
  const COMMON = String.raw`
19
7
  const r = (name) => iri('http://www.w3.org/1999/02/22-rdf-syntax-ns#' + name);
@@ -21,12 +9,6 @@ const s = (name) => iri('http://www.w3.org/2000/01/rdf-schema#' + name);
21
9
  const o = (name) => iri('http://www.w3.org/2002/07/owl#' + name);
22
10
  const e = (name) => iri('https://eyereasoner.github.io/eyemind/entailment#' + name);
23
11
  const t = (a, p, b) => rdf(a, p, b, G);
24
- implied_by(ent_resource(iri(A)), is_atom(A));
25
- implied_by(ent_resource(bnode(A, B)), [is_atom(A), is_atom(B)]);
26
- implied_by(ent_resource(triple(A, B, C)), 'true');
27
- implies(rdf(S, P, O, G), ent_graph(G));
28
- implies(rdf(S, P, O, G), [ent_node(S, G), ent_node(P, G), ent_node(O, G)]);
29
-
30
12
  // RDFS class/property propagation.
31
13
  implies([t(P, s('domain'), C), t(X, P, Y)], t(X, r('type'), C));
32
14
  implies([t(P, s('range'), C), t(X, P, Y)], t(Y, r('type'), C));
@@ -165,15 +147,37 @@ for (const kind of ['hasValue', 'someValuesFrom', 'allValuesFrom']) {
165
147
  }
166
148
  `;
167
149
 
168
- const OUTPUT = String.raw`
169
- // Separate report triples from the ontology so a conflict report does not
170
- // create more ontology consequences. All conflicts are retained, without
171
- // stopping at the first contradiction or concluding arbitrary triples.
172
- implies([ent_conflict(R, X, P, Y, G)], [
173
- ent_report(B, r('type'), e('Conflict'), G), ent_report(B, e('rule'), literal(R, datatype('http://www.w3.org/2001/XMLSchema#string')), G),
174
- ent_report(B, e('focus'), X, G), ent_report(B, e('left'), P, G), ent_report(B, e('right'), Y, G),
175
- ]);
176
- implies([rdf(S, iri(P), O, G), ent_resource(S), not(ent_base(S, iri(P), O, G))], result_rdf(S, iri(P), O, G));
177
- implies(ent_report(S, P, O, G), result_rdf(S, P, O, G));
178
- query(result_rdf(S, P, O, G));
150
+ const ADDITIONS = String.raw`
151
+ // Explicit differences, disjoint lists and reflexive properties also yield
152
+ // useful positive consequences, not only conflict diagnostics.
153
+ implies(t(X, o('differentFrom'), Y), t(Y, o('differentFrom'), X));
154
+ implies([t(P, r('type'), o('ReflexiveProperty')), ent_node(X, G), ent_resource(X)], t(X, P, X));
155
+ for (const property of ['members', 'distinctMembers']) {
156
+ implies([t(A, r('type'), o('AllDifferent')), t(A, o(property), L), ent_pair(L, X, Y, G)],
157
+ [t(X, o('differentFrom'), Y), t(Y, o('differentFrom'), X)]);
158
+ }
159
+ implies([t(A, r('type'), o('AllDisjointClasses')), t(A, o('members'), L), ent_pair(L, X, Y, G)],
160
+ [t(X, o('disjointWith'), Y), t(Y, o('disjointWith'), X)]);
161
+ implies([t(A, r('type'), o('AllDisjointProperties')), t(A, o('members'), L), ent_pair(L, X, Y, G)],
162
+ [t(X, o('propertyDisjointWith'), Y), t(Y, o('propertyDisjointWith'), X)]);
163
+ implies([t(P, o('propertyDisjointWith'), Q), t(X, P, V), t(Y, Q, V)], t(X, o('differentFrom'), Y));
164
+ implies([t(P, o('propertyDisjointWith'), Q), t(X, P, V), t(X, Q, W)], t(V, o('differentFrom'), W));
165
+ implies([t(P, r('type'), o('FunctionalProperty')), t(X, P, V), t(Y, P, W), t(V, o('differentFrom'), W)], t(X, o('differentFrom'), Y));
166
+ // Literal membership and exact numeric/boolean/string value comparisons.
167
+ // Datatype declarations are scoped to the vocabulary actually used by a graph.
168
+ implies([ent_node(iri(D), G), rv_supported(iri(D))], t(iri(D), r('type'), s('Datatype')));
169
+ implies([rdf(_, _, T, G), rv_literal(T)], ent_literal(T, G));
170
+ implies([ent_literal(T, G), rv_datatype(T, D), rv_valid(T)], t(T, r('type'), D));
171
+ implies([ent_literal(T, G), ent_node(D, G), rv_supported(D), rv_member(T, D)], t(T, r('type'), D));
172
+ implies([ent_literal(T, G), rv_datatype(T, D), rv_supported(D), rdf(T, r('type'), D, G), not(rv_valid(T))],
173
+ ent_conflict('dt-not-type', T, r('type'), D, G));
174
+ implies([ent_literal(T, G), rv_exact(T), rdf(T, r('type'), D, G), rv_integer_datatype(D), not(rv_member(T, D))],
175
+ ent_conflict('dt-not-type', T, r('type'), D, G));
176
+ implies([ent_literal(A, G), ent_literal(B, G), not_identical(A, B), rv_same(A, B)], t(A, o('sameAs'), B));
177
+ implies([ent_literal(A, G), ent_literal(B, G), rv_different(A, B)], t(A, o('differentFrom'), B));
178
+ // Qualified datatype restrictions use value-space membership as well.
179
+ implies([t(C, o('maxQualifiedCardinality'), N), ent_cardinality(N, K), t(C, o('onProperty'), P), t(C, o('onDataRange'), D),
180
+ t(X, r('type'), C), t(X, P, V), rv_member(V, D)], ent_qualified(C, K, X, P, V, G));
179
181
  `;
182
+
183
+ export const owl2rlRules = COMMON + RDFS + OWL + ADDITIONS;