diff --git a/PSOA2X/pom.xml b/PSOA2X/pom.xml index aa86ebd9..b8af133e 100644 --- a/PSOA2X/pom.xml +++ b/PSOA2X/pom.xml @@ -14,7 +14,7 @@ org.antlr antlr3-maven-plugin - 3.4 + 3.5.2 @@ -72,7 +72,7 @@ org.antlr antlr-runtime - 3.4 + 3.5.2 jar compile diff --git a/PSOA2X/src/main/antlr3/imports/PSOAPS.tokens b/PSOA2X/src/main/antlr3/imports/PSOAPS.tokens index 78a4c33e..af55229a 100644 --- a/PSOA2X/src/main/antlr3/imports/PSOAPS.tokens +++ b/PSOA2X/src/main/antlr3/imports/PSOAPS.tokens @@ -1,61 +1,62 @@ -T__59=59 -T__60=60 -T__61=61 -ALPHA=4 -AND=5 -BASE=6 -COMMENT=7 -DEPSIGN=8 -DIGIT=9 -DOCUMENT=10 -ECHAR=11 -EOL=12 -EQUAL=13 -EXISTS=14 -EXTERNAL=15 -FALSITY=16 -FORALL=17 -GREATER=18 -GROUP=19 -HEX=20 -IMPLICATION=21 -IMPORT=22 -INSTANCE=23 -IRI=24 -IRI_REF=25 -IRI_REF_CHARACTERS=26 -LESS=27 -LITERAL=28 -LOCAL=29 -LPAR=30 -LSQBR=31 -MULTI_LINE_COMMENT=32 -NAF=33 -NAMESPACE=34 -NUMBER=35 -OR=36 -PERCENT=37 -PLX=38 -PN_CHARS=39 -PN_CHARS_BASE=40 -PN_CHARS_U=41 -PN_LOCAL=42 -PN_LOCAL_ESC=43 -PN_PREFIX=44 -PREFIX=45 -PSOA=46 -RPAR=47 -RSQBR=48 -SHORTCONST=49 -SLOT=50 -SLOT_ARROW=51 -STRING=52 -SUBCLASS=53 -SYMSPACE_OPER=54 -TOP=55 -TUPLE=56 -VAR_ID=57 -WHITESPACE=58 -'@'=59 -'no'=60 -'yes'=61 +T__60=60 +T__61=61 +T__62=62 +ALPHA=4 +AND=5 +BASE=6 +COMMENT=7 +DEPSIGN=8 +DIGIT=9 +DOCUMENT=10 +ECHAR=11 +EOL=12 +EQUAL=13 +EXISTS=14 +EXTERNAL=15 +FALSITY=16 +FORALL=17 +GREATER=18 +GROUP=19 +HEX=20 +IMPLICATION=21 +IMPORT=22 +INSTANCE=23 +IRI=24 +IRI_REF=25 +IRI_REF_CHAR=26 +LESS=27 +LITERAL=28 +LOCAL=29 +LPAR=30 +LSQBR=31 +MULTI_LINE_COMMENT=32 +NAF=33 +NAMESPACE=34 +NUMBER=35 +OIDLESSEMBATOM=36 +OR=37 +PERCENT=38 +PLX=39 +PN_CHARS=40 +PN_CHARS_BASE=41 +PN_CHARS_U=42 +PN_LOCAL=43 +PN_LOCAL_ESC=44 +PN_PREFIX=45 +PREFIX=46 +PSOA=47 +RPAR=48 +RSQBR=49 +SHORTCONST=50 +SLOT=51 +SLOT_ARROW=52 +STRING=53 +SUBCLASS=54 +SYMSPACE_OPER=55 +TOP=56 +TUPLE=57 +VAR_ID=58 +WHITESPACE=59 +'@'=60 +'no'=61 +'yes'=62 diff --git a/PSOA2X/src/main/java/org/ruleml/psoa/psoa2x/common/Translator.java b/PSOA2X/src/main/java/org/ruleml/psoa/psoa2x/common/Translator.java index 1bedd33e..e7082076 100644 --- a/PSOA2X/src/main/java/org/ruleml/psoa/psoa2x/common/Translator.java +++ b/PSOA2X/src/main/java/org/ruleml/psoa/psoa2x/common/Translator.java @@ -82,4 +82,4 @@ public Map getQueryVarMap() public List getQueryVars() { return new ArrayList(m_queryVarMap.keySet()); } -} \ No newline at end of file +} diff --git a/PSOACore/pom.xml b/PSOACore/pom.xml index 7c57979c..47c5dff1 100644 --- a/PSOACore/pom.xml +++ b/PSOACore/pom.xml @@ -11,7 +11,7 @@ org.antlr antlr3-maven-plugin - 3.4 + 3.5.2 @@ -68,7 +68,7 @@ org.antlr antlr-runtime - 3.4 + 3.5.2 jar compile diff --git a/PSOACore/src/main/antlr3/org/ruleml/psoa/TreeWalkerTemplate.g b/PSOACore/src/main/antlr3/org/ruleml/psoa/TreeWalkerTemplate.g index 1c26f1e2..36343969 100644 --- a/PSOACore/src/main/antlr3/org/ruleml/psoa/TreeWalkerTemplate.g +++ b/PSOACore/src/main/antlr3/org/ruleml/psoa/TreeWalkerTemplate.g @@ -114,6 +114,7 @@ external psoa : ^(PSOA term? ^(INSTANCE term) tuple* slot*) + | ^(OIDLESSEMBATOM ^(INSTANCE term) tuple* slot*) ; tuple diff --git a/PSOACore/src/main/antlr3/org/ruleml/psoa/analyzer/KBInfoCollector.g b/PSOACore/src/main/antlr3/org/ruleml/psoa/analyzer/KBInfoCollector.g index 0c50b0b3..0e4a8e18 100644 --- a/PSOACore/src/main/antlr3/org/ruleml/psoa/analyzer/KBInfoCollector.g +++ b/PSOACore/src/main/antlr3/org/ruleml/psoa/analyzer/KBInfoCollector.g @@ -237,6 +237,14 @@ psoa[boolean isAtomicFormula] if (isAtomicFormula) addPsoaTermInfo($pred.tree.toStringTree(), arities, oid != null, hasIndepTuple, hasMultiTuple, hasSlot); } + | ^(OIDLESSEMBATOM ^(INSTANCE term) + ((t=tuple { arities.add($t.length); hasIndepTuple = !$t.dep; }) + (t=tuple { arities.add($t.length); if (!$t.dep) hasIndepTuple = true; hasMultiTuple = true; } )*)? + (slot { hasSlot = true; })*) + { + if (isAtomicFormula) + addPsoaTermInfo($pred.tree.toStringTree(), arities, false, hasIndepTuple, hasMultiTuple, hasSlot); + } ; tuple returns [int length, boolean dep] diff --git a/PSOACore/src/main/antlr3/org/ruleml/psoa/analyzer/SchemalessChecker.g b/PSOACore/src/main/antlr3/org/ruleml/psoa/analyzer/SchemalessChecker.g index 74904a73..dd0534b9 100644 --- a/PSOACore/src/main/antlr3/org/ruleml/psoa/analyzer/SchemalessChecker.g +++ b/PSOACore/src/main/antlr3/org/ruleml/psoa/analyzer/SchemalessChecker.g @@ -208,7 +208,8 @@ external ; psoa - : ^(PSOA term? ^(INSTANCE term) tuple* (slots+=slot)*) + : ^(OIDLESSEMBATOM ^(INSTANCE term) tuple* slot*) + | ^(PSOA term? ^(INSTANCE term) tuple* (slots+=slot)*) ; tuple diff --git a/PSOACore/src/main/antlr3/org/ruleml/psoa/parser/PSOAPS.g b/PSOACore/src/main/antlr3/org/ruleml/psoa/parser/PSOAPS.g index a2a7f0c4..046627b7 100644 --- a/PSOACore/src/main/antlr3/org/ruleml/psoa/parser/PSOAPS.g +++ b/PSOACore/src/main/antlr3/org/ruleml/psoa/parser/PSOAPS.g @@ -14,6 +14,7 @@ options tokens { PSOA; + OIDLESSEMBATOM; TUPLE; SLOT; LITERAL; @@ -41,6 +42,7 @@ tokens @lexer::header { package org.ruleml.psoa.parser; + import static org.ruleml.psoa.utils.IOUtil.*; } @lexer::members { @@ -69,7 +71,7 @@ tokens } /** - * Get the full IRI form of an IRI prefix + * Get full IRI of an IRI prefix */ protected String getNamespace(String prefix) { @@ -92,7 +94,7 @@ tokens } /** - * Get full IRI from a namespace-prefixed IRI + * Get full IRI from a namespace-prefixed IRI, by concatenating namespace with localName */ protected String getFullIRI(String ns, String localName) { @@ -136,6 +138,16 @@ tokens throw new PSOARuntimeException("Whitespace is expected before " + input.get(input.index()).getText()); } } + + public void checkNoPrecedingWhitespace() { + if (input.get(input.index() - 1).getType() == WHITESPACE) { + throw new PSOARuntimeException("There must be no whitespace before " + input.get(input.index()).getText()); + } + } + + public boolean hasPrecedingWhitespace() { + return (input.get(input.index() - 1).getType() == WHITESPACE); + } } document @@ -214,24 +226,58 @@ formula returns [boolean isValidHead, boolean isAtomic] | naf_formula | atomic { $isAtomic = true; } -> atomic | (external_term { $isValidHead = false; } -> external_term) - (psoa_rest { $isAtomic = true; } -> ^(PSOA $formula psoa_rest))? + ({!hasPrecedingWhitespace()}? psoa_rest { $isAtomic = true; } -> ^(PSOA $formula psoa_rest))? ; naf_formula : NAF LPAR formula RPAR-> ^(NAF["NAF"] formula) ; -atomic +/* + * ANTLR rule for parsing atomic formulas + * + * atomic matches atomic formulas at the KB top-level. It divides two categories + * of atomic formulas across its two alternatives in this order: + * + * (1) Equality ("=") and subclass ("##") relations + * (2) Other formulas represented by the match result of internal_term + * + * internal_term has a boolean argument called isAtomic: + * + * If true, its match result is an atomic formula + * + * If false, it is a subterm of an atomic formula, + * which is not at the KB top-level and therefore not an atomic formula + * + * atomic provisionally assumes it is matching an equality or subclass relation by + * invoking its first alternative. If it fails, it backtracks to the second alternative. + * Backtracking is not a default behavior of ANTLR rules and must be enabled (at the + * granularity of an individual rule) via ANTLR's {backtrack = true;} option. + * + * Similarly, memoization is enabled via ANTLR's {memoize = true;} option. It saves the partial + * successes of failed matches for later use in backtracked alternatives. In particular, + * if left_term is matched in the first alternative but is not followed by either + * an EQUAL or SUBCLASS token, its memoized match result is re-used upon backtracking to + * the second alternative where its isAtomic argument becomes true. + * + * Since ANTLR parses all text in a single left-to-right pass and the correct value of + * left_term's isAtomic argument is known only after left_term is matched, backtracking is + * necessary here. + */ + +atomic options {backtrack = true; memoize = true;} @after { if ($tree.getChildCount() == 1 && $left_term.isSimple) throw new PSOARuntimeException("Simple term cannot be an atomic formula:" + $left_term.text); } - : left_term=internal_term ((EQUAL | SUBCLASS)^ term)? + : left_term=internal_term[false] ((EQUAL | SUBCLASS)^ term[false]) // Check for "=" or "##" tokens/operators + | left_term=internal_term[true] // Otherwise, backtrack here and + // set left_term.isAtomic = true (i.e., toggle left_term as a top-level atomic formula) ; -term - : internal_term +term[boolean isAtomic] + : internal_term[isAtomic] | external_term ; @@ -241,11 +287,11 @@ simple_term ; external_term - : EXTERNAL LPAR simple_term LPAR (term ({ checkPrecedingWhitespace(); } term)*)? RPAR RPAR + : EXTERNAL LPAR simple_term LPAR (term[false] ({ checkPrecedingWhitespace(); } term[false])*)? RPAR RPAR -> ^(EXTERNAL ^(PSOA ^(INSTANCE simple_term) ^(TUPLE DEPSIGN["+"] term*))) ; -internal_term returns [boolean isSimple] +internal_term[boolean isAtomic] returns [boolean isSimple] scope { boolean inLTNF; @@ -267,7 +313,44 @@ scope : (simple_term -> simple_term) (LPAR (tuples_and_slots { $internal_term::inLTNF &= $tuples_and_slots.inLTNF; })? RPAR { $isSimple = false; } -> ^(PSOA ^(INSTANCE $internal_term) tuples_and_slots?))? - (psoa_rest { $isSimple = false; $internal_term::inLTNF &= $psoa_rest.inLTNF; } -> ^(PSOA $internal_term psoa_rest))* + ({ !hasPrecedingWhitespace() }? psoa_rest { $isSimple = false; $internal_term::inLTNF &= $psoa_rest.inLTNF; } + -> ^(PSOA $internal_term psoa_rest))* + | emb_atom_chain[isAtomic] { $isSimple = false; $internal_term::inLTNF &= $emb_atom_chain.inLTNF; } + ; + +emb_atom_chain_rest + : { !hasPrecedingWhitespace() }? psoa_rest + ; + +/* + * In the following, "OID-embedded" means "embedded in the OID position". + * What we will call "the chain o#a#b" of a top-level atom + * o#a#b(...) is its "initial part parsed as an OID-embedded atom o#a + * followed by the predicate b" of the corresponding oidless atom b(...). + */ + +/* + * ANTLR rule for parsing embedded oidless atoms + */ + +emb_atom_chain[boolean isAtomic] returns [boolean inLTNF] +scope +{ + boolean firstLinkInChain; +} +@init +{ + $emb_atom_chain::firstLinkInChain = true; +} + : (head_link=psoa_rest {$emb_atom_chain.inLTNF = $psoa_rest.inLTNF; } // Match "#a" of "#a#b" + -> { isAtomic }? ^(PSOA psoa_rest) // Designate a top-level oidless atom as a PSOA atom + -> ^(OIDLESSEMBATOM psoa_rest)) // Otherwise, designate an embedded oidless atom as an OIDLESSEMBATOM atom + ((emb_atom_chain_rest // Match "#b" of "#a#b" + -> { $emb_atom_chain::firstLinkInChain && $isAtomic }? // Test if matched "#a" and on KB top-level + ^(PSOA ^(OIDLESSEMBATOM $head_link) emb_atom_chain_rest) // Wrap "#a" as the OID-embedded atom of "#a#b" + -> ^(PSOA $emb_atom_chain emb_atom_chain_rest)) // Otherwise, wrap "#a#b" as the OID-embedded atom of emb_atom_chain_rest + { $emb_atom_chain::firstLinkInChain = false; } // emb_atom_chain_rest has succeeded at least once + )* ; psoa_rest returns [boolean inLTNF] @@ -283,7 +366,7 @@ scope { $inLTNF = $psoa_rest::tsInLTNF; } - : INSTANCE simple_term (LPAR (ts=tuples_and_slots { $psoa_rest::tsInLTNF &= $ts.inLTNF; })? RPAR)? + : INSTANCE { checkNoPrecedingWhitespace(); } simple_term (LPAR (ts=tuples_and_slots { $psoa_rest::tsInLTNF &= $ts.inLTNF; })? RPAR)? -> ^(INSTANCE simple_term) tuples_and_slots? ; @@ -291,10 +374,10 @@ scope * tuples_and_slots parses a sequence of tuples and slots inside a PSOA atom. * * The analysis considers two cases, distinguished by the presence (absence) - * of an implicit tuple, a sequence of terms unenclosed by square brackets. + * of an implicit tuple, a sequence of terms not enclosed by square brackets. * * An implicit tuple: - * * cannot be written in an atom containing conventional ("explicit") tuples, + * * cannot be written in an atom containing explicit tuples, * * requires its surrounding atom to be written in left tuple normal form. * * An atom without an implicit tuple allows explicit tuples and slots to be @@ -320,42 +403,48 @@ scope // Track the indexes of the earliest slot and latest tuple after it { int firstSlotIndex; int lastTupleIndex; + int line; + boolean hasSlot; + boolean hasExplTuple; + boolean preSlotArrowTuple; } @init // Set initial values satisfying lastTupleIndex < firstSlotIndex (last tuple is before first slot) { $inLTNF = true; $tuples_and_slots::firstSlotIndex = Integer.MAX_VALUE; $tuples_and_slots::lastTupleIndex = 0; + $tuples_and_slots::hasSlot = false; + $tuples_and_slots::hasExplTuple = false; + $tuples_and_slots::preSlotArrowTuple = false; + $tuples_and_slots::line = input.LT(1).getLine(); } @after // The sequence is in LTNF iff the first slot has lexical index greater than or equal to the last tuple index { $inLTNF = $tuples_and_slots::firstSlotIndex >= $tuples_and_slots::lastTupleIndex; } - : { boolean hasSlot = false; boolean hasExplTuple = false; boolean preSlotArrowTuple = false; - int line = input.LT(1).getLine();} - ((terms += term {preSlotArrowTuple = false; }) | (tuple {preSlotArrowTuple = true; hasExplTuple = true; })) + : ((terms += term[false] {$tuples_and_slots::preSlotArrowTuple = false; }) | (tuple {$tuples_and_slots::preSlotArrowTuple = true; $tuples_and_slots::hasExplTuple = true; })) // If "terms" is non-empty, its contents belong to a single // implicit tuple, except for the last term, which is the slot name. ({ checkPrecedingWhitespace(); } - ((terms += term {preSlotArrowTuple = false; }) | (tuple {preSlotArrowTuple = true; hasExplTuple = true; })))* - ( SLOT_ARROW first_slot_value=term { $tuples_and_slots::firstSlotIndex = input.index(); hasSlot = true; } (slot | (tuple {$tuples_and_slots::lastTupleIndex = input.index(); hasExplTuple = true; }))* )? + ((terms += term[false] {$tuples_and_slots::preSlotArrowTuple = false; }) | (tuple {$tuples_and_slots::preSlotArrowTuple = true; $tuples_and_slots::hasExplTuple = true; })))* + ( SLOT_ARROW first_slot_value=term[false] { $tuples_and_slots::firstSlotIndex = input.index(); $tuples_and_slots::hasSlot = true; } (slot | (tuple {$tuples_and_slots::lastTupleIndex = input.index(); $tuples_and_slots::hasExplTuple = true; }))* )? { - if (hasSlot && preSlotArrowTuple) + if ($tuples_and_slots::hasSlot && $tuples_and_slots::preSlotArrowTuple) { - throw new PSOARuntimeException("Explicit tuple as slot name at line " + line); + throw new PSOARuntimeException("Explicit tuple as slot name at line " + $tuples_and_slots::line); } - else if (hasExplTuple && hasSlot && $terms == null) + else if ($tuples_and_slots::hasExplTuple && $tuples_and_slots::hasSlot && $terms == null) { - throw new PSOARuntimeException("Missing valid slot name at line " + line); + throw new PSOARuntimeException("Missing valid slot name at line " + $tuples_and_slots::line); } - else if (hasExplTuple && ((!hasSlot && $terms != null) || (hasSlot && $terms.size() > 1))) + else if ($tuples_and_slots::hasExplTuple && ((!$tuples_and_slots::hasSlot && $terms != null) || ($tuples_and_slots::hasSlot && $terms.size() > 1))) { - throw new PSOARuntimeException("Implicit tuple in atom with one or more explicit tuples at line " + line); + throw new PSOARuntimeException("Implicit tuple in atom with one or more explicit tuples at line " + $tuples_and_slots::line); } } - -> {!hasSlot && hasExplTuple}? // explicit tuples, no implicit tuple + -> {!$tuples_and_slots::hasSlot && $tuples_and_slots::hasExplTuple}? // explicit tuples, no implicit tuple tuple+ - -> {!hasSlot}? // single implicit tuple + -> {!$tuples_and_slots::hasSlot}? // single implicit tuple ^(TUPLE DEPSIGN["+"] {getTupleTree($terms, $terms.size()) } ) -> {$terms.size() == 1}? // no implicit tuple, leading slot // normalize to right-slot normal form @@ -367,13 +456,13 @@ scope // Track the indexes of the earliest slot and latest tuple after it ; tuple - : DEPSIGN LSQBR (term ({ checkPrecedingWhitespace(); } term)*)? RSQBR -> ^(TUPLE DEPSIGN term*) - | LSQBR (term ({ checkPrecedingWhitespace(); } term)*)? RSQBR -> ^(TUPLE DEPSIGN["+"] term*) // Tuples with no dependency signs are treated as dependent, may be DEPRECATED in the future + : DEPSIGN LSQBR (term[false] ({ checkPrecedingWhitespace(); } term[false])*)? RSQBR -> ^(TUPLE DEPSIGN term*) + | LSQBR (term[false] ({ checkPrecedingWhitespace(); } term[false])*)? RSQBR -> ^(TUPLE DEPSIGN["+"] term*) // Tuples with no dependency signs are treated as dependent, may be DEPRECATED in the future ; slot : - name=term SLOT_ARROW value=term -> ^(SLOT DEPSIGN[$SLOT_ARROW.text.substring(0, 1)] $name $value) + name=term[false] SLOT_ARROW value=term[false] -> ^(SLOT DEPSIGN[$SLOT_ARROW.text.substring(0, 1)] $name $value) ; /* @@ -383,10 +472,13 @@ slot */ constant +@init { + String localConstName = new String(); +} : iri -> ^(SHORTCONST iri) | const_string -> const_string | NUMBER -> ^(SHORTCONST NUMBER) - | { String localConstName; } + | //{ String localConstName; } PN_LOCAL { if ($PN_LOCAL.text.startsWith("_")) localConstName = $PN_LOCAL.text.substring(1); @@ -425,7 +517,7 @@ variable answer : 'yes' | 'no' - | (term EQUAL term)+ + | (term[false] EQUAL term[false])+ ; iri returns [String fullIRI] @@ -443,13 +535,13 @@ curie returns [String fullIRI] // Comments and whitespace: WHITESPACE : (' '|'\t'|'\r'|'\n')+ { $channel = HIDDEN; } ; COMMENT : '%' ~('\n')* { $channel = HIDDEN; } ; -MULTI_LINE_COMMENT : '' +MULTI_LINE_COMMENT : '' { $channel=HIDDEN; } - { + { if (printDeprecatedCommentWarning) { - System.out.println("Warning: XML-style comment blocks (delimited by '') are now deprecated and will be removed in a future release."); + printErrln("Warning: XML-style comment blocks (delimited by '') are now deprecated and will be removed in a future release."); printDeprecatedCommentWarning = false; - } + } } | '/*' (options {greedy=false;} : .*) '*/' { $channel=HIDDEN; } ; diff --git a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Concatenater.g b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Concatenater.g index 90aedec0..19beef37 100644 --- a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Concatenater.g +++ b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Concatenater.g @@ -124,7 +124,8 @@ external ; psoa - : ^(PSOA term? ^(INSTANCE term) tuple* slot*) + : ^(OIDLESSEMBATOM ^(INSTANCE term) tuple* slot*) + | ^(PSOA term? ^(INSTANCE term) tuple* slot*) ; tuple diff --git a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/ConjunctiveHeadSplitter.g b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/ConjunctiveHeadSplitter.g index ae9df918..4f4082bc 100644 --- a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/ConjunctiveHeadSplitter.g +++ b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/ConjunctiveHeadSplitter.g @@ -247,7 +247,8 @@ external ; psoa - : ^(PSOA term? ^(INSTANCE term) tuple* slot*) + : ^(OIDLESSEMBATOM ^(INSTANCE term) tuple* slot*) + | ^(PSOA term? ^(INSTANCE term) tuple* slot*) ; tuple diff --git a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Descributor.g b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Descributor.g index b23ca14a..ec4363f0 100644 --- a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Descributor.g +++ b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Descributor.g @@ -224,7 +224,8 @@ external ; psoa[boolean isAtomicFormula] - : ^(PSOA oid=term? ^(INSTANCE op=term) tuples+=tuple* slots+=slot*) + : ^(OIDLESSEMBATOM ^(INSTANCE term) tuple* slot*) + | ^(PSOA oid=term? ^(INSTANCE op=term) tuples+=tuple* slots+=slot*) -> { !isAtomicFormula || oid == null }? ^(PSOA $oid? ^(INSTANCE $op) tuple* slot*) -> { getDescributorTree($oid.tree, $op.tree, $tuples, $slots) } diff --git a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/EmbeddedObjectifier.g b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/EmbeddedObjectifier.g new file mode 100644 index 00000000..c4f01d4f --- /dev/null +++ b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/EmbeddedObjectifier.g @@ -0,0 +1,333 @@ +/** + * This grammar file is used to generate a transformer for embedded objectification. + **/ + +tree grammar EmbeddedObjectifier; + +options +{ + output = AST; + ASTLabelType = CommonTree; + tokenVocab = PSOAPS; + rewrite = false; + k = 1; +} + +@header +{ + package org.ruleml.psoa.transformer; + + import java.util.Collections; + import java.util.Set; + import java.util.HashSet; + import java.util.Map; + import java.util.LinkedHashMap; + import java.util.Vector; + + import static org.ruleml.psoa.FreshNameGenerator.*; + import static org.ruleml.psoa.utils.IOUtil.*; + import org.ruleml.psoa.analyzer.*; +} + +@members +{ + // :BEGIN: These five fields are copied from Objectifier.g + + private boolean m_isRuleBody = false; + private boolean m_isQuery = false; + private boolean m_isGroundFact = false; + + private Set m_localConsts; + private Set m_clauseVars = new HashSet(); + + // :END: + + /* + + m_newPositiveExistsVarNodes stores AST nodes describing existential variables + occurring in positive contexts (rule conclusions and facts) + while + m_newNegativeExistsVarNodes stores existential variables + in negative contexts (rule conditions and queries). + + */ + + private Map m_newPositiveExistsVarNodes = new LinkedHashMap(); + private Map m_newNegativeExistsVarNodes = new LinkedHashMap(); + + // :BEGIN: The next four methods are adapted from Objectifier.g + + public void setExcludedLocalConstNames(Set excludedConstNames) + { + m_localConsts = excludedConstNames; + } + + private CommonTree newVarNode() + { + // During clause-tree traversal, generate a fresh variable name using an increasing + // set of already encountered clause variable names. If this name is encountered later, + // it will be modified in newForallVarsTree(). + String name = freshVarName(m_clauseVars); + CommonTree node = (CommonTree)adaptor.create(VAR_ID, name); + + if (m_isRuleBody || m_isQuery) + m_newNegativeExistsVarNodes.put(name, node); + else + m_newPositiveExistsVarNodes.put(name, node); + + return (CommonTree)adaptor.dupNode(node); + } + + private void checkNewExistVars() + { + for (Map.Entry entry : m_newPositiveExistsVarNodes.entrySet()) + { + String var = entry.getKey(); + CommonTree node = entry.getValue(); + + // Rename the variable name if it was encountered in the clause + if (m_clauseVars.contains(var)) + { + node.getToken().setText(freshVarName(m_clauseVars)); + } + } + + m_newPositiveExistsVarNodes.clear(); + + for (Map.Entry entry : m_newNegativeExistsVarNodes.entrySet()) + { + String var = entry.getKey(); + CommonTree node = entry.getValue(); + + // Rename the variable name if it was encountered in the clause + if (m_clauseVars.contains(var)) + { + node.getToken().setText(freshVarName(m_clauseVars)); + } + } + + m_newNegativeExistsVarNodes.clear(); + } + + private CommonTree newExistsVarsTree(Map existVarNodes) + { + CommonTree root = (CommonTree) adaptor.nil(); + + for (Map.Entry entry : existVarNodes.entrySet()) + { + String var = entry.getKey(); + CommonTree node = entry.getValue(); + + // Rename the variable name if it was encountered in the clause + if (m_clauseVars.contains(var)) + { + node.getToken().setText(freshVarName(m_clauseVars)); + } + + adaptor.addChild(root, node); + } + + existVarNodes.clear(); + return root; + } + + // :END: +} + +document + : ^(DOCUMENT base? prefix* importDecl* group?) + ; + +base + : ^(BASE IRI_REF) + ; + +prefix + : ^(PREFIX NAMESPACE IRI_REF) + ; + +importDecl + : ^(IMPORT IRI_REF IRI_REF?) + ; + +group + : ^(GROUP group_element*) + ; + +group_element + : rule + | group + ; + +query +@init +{ + m_isQuery = true; +} +@after +{ + checkNewExistVars(); + m_clauseVars.clear(); + m_isQuery = false; +} + : formula + -> { m_newNegativeExistsVarNodes.isEmpty() }? formula + -> ^(EXISTS { newExistsVarsTree(m_newNegativeExistsVarNodes) } formula) + ; + +rule +@init +{ + // Reset variable generator before processing each (PSOA RuleML Presentation Syntax) RULE nonterminal + // (http://wiki.ruleml.org/index.php/PSOA_RuleML#Monolithic_EBNF_for_PSOA_RuleML_Presentation_Syntax) + resetVarGen(); +} +@after +{ + checkNewExistVars(); + m_clauseVars.clear(); +} + : ^(FORALL (VAR_ID { m_clauseVars.add($VAR_ID.text); })+ clause) // Add Forall variable(s) to m_clauseVars for ground heuristic below + | clause + ; + +/* + * ANTLR rule for transforming clause trees + * + * A clause is either an IMPLICATION (i.e., a PSOA rule) subtree containing a head and a formula, + * or a standalone head (i.e., a PSOA fact) subtree: + * + * In IMPLICATION subtrees, oidless embedded atoms are assigned existential variable OIDs. + * These variables are gathered in m_newPositiveExistsVarNodes if they occur in a positive + * context and in m_newNegativeExistsVarNodes if they occur in a negative one. + * + * In standalone head subtrees, the m_clauseVars.isEmpty() heuristic determines if the head is ground; + * the set m_clauseVars is populated with variable names listed in the possibly enclosing Forall clause; + * m_clauseVars is populated in the FORALL alternative of rule before clause is conjunctively invoked: + * + * If m_clauseVars is empty, then presumably the standalone head subtree has no variables, making it ground. + * + * All oidless embedded atoms found in the standalone head subtree are objectified with Skolem constant OIDs. + */ + +clause + : ^(IMPLICATION + { m_isGroundFact = false; } // An IMPLICATION is not a PSOA ground fact + head + { m_isRuleBody = true; } // Now in the IMPLICATION's formula (rule body) + formula + { m_isRuleBody = false; } // No longer in the IMPLICATION's formula + ) + -> { (m_newPositiveExistsVarNodes.isEmpty()) + && m_newNegativeExistsVarNodes.isEmpty() }? // No embedded OIDs in either conclusion (head) or condition (body) + ^(IMPLICATION head formula) + -> { m_newPositiveExistsVarNodes.isEmpty() }? // Embedded OIDs in condition, none in conclusion + ^(IMPLICATION head ^(EXISTS { newExistsVarsTree(m_newNegativeExistsVarNodes) } formula)) + -> { m_newNegativeExistsVarNodes.isEmpty() }? // Embedded OIDs in conclusion, none in condition + ^(IMPLICATION ^(EXISTS { newExistsVarsTree(m_newPositiveExistsVarNodes) } head) formula) + -> ^(IMPLICATION // Embedded OIDs in both conclusion and condition + ^(EXISTS { newExistsVarsTree(m_newPositiveExistsVarNodes) } head) + ^(EXISTS { newExistsVarsTree(m_newNegativeExistsVarNodes) } formula)) + | { m_isGroundFact = m_clauseVars.isEmpty(); } // The fact (standalone head subtree) is ground + head + -> { !m_isGroundFact && !m_newPositiveExistsVarNodes.isEmpty() }? // Not a ground fact, and there are generated OID variables + ^(EXISTS { newExistsVarsTree(m_newPositiveExistsVarNodes) } head) + -> head // Otherwise, the fact is ground, or there were no generated OID variables + ; + +head + : atomic + | ^(AND head+) + | ^(EXISTS VAR_ID+ head) + ; + +formula + : ^(AND formula+) + | ^(OR formula+) + | ^(EXISTS VAR_ID+ formula) + | FALSITY + | naf_formula + | atomic + | external + ; + +naf_formula + : ^(NAF formula) + ; + +atomic + : atom + | equal + | subclass + ; + +atom + : psoa + ; + +equal + : ^(EQUAL term term) + ; + +subclass + : ^(SUBCLASS term term) + ; + +term + : constant + | VAR_ID + { + m_clauseVars.add($VAR_ID.text); // Add variable name to avoid later collisions with generated variables (e.g., for OIDs) + } + | psoa + | external + ; + +external + : ^(EXTERNAL psoa) + ; + +/* + * ANTLR rule for transforming psoa trees + * + * psoa is where all oidless embedded atoms are objectified. + * + * psoa uses the previously determined boolean m_isGroundFact + * to determine whether to emit a Skolem constant OID (_1, _2, ...) + * or an existential variable OID. + * + * The method newVarNode() does the work of both building the AST node + * representing the OID and putting it into one of the m_newPositiveExistsVarNodes + * or m_newNegativeExistsVarNodes Maps, depending on the context of the + * surrounding atom. + */ + +psoa + : ^(PSOA term? ^(INSTANCE term) tuple* slot*) + | ^(OIDLESSEMBATOM ^(INSTANCE term) tuple* slot*) + -> { m_isGroundFact }? // The oidless embedded atom occurs in a ground fact + ^(PSOA ^(SHORTCONST LOCAL[freshConstName(m_localConsts)]) ^(INSTANCE term) tuple* slot*) // Generate a Skolem constant OID + -> // Here we need to gather introduced variables into an Exists clause: + ^(PSOA { newVarNode() } ^(INSTANCE term) tuple* slot*) // Otherwise, generate an existential variable OID, put it in the appropriate map + ; + +tuple + : ^(TUPLE DEPSIGN term*) + ; + +slot + : ^(SLOT DEPSIGN term term) + ; + +constant + : ^(LITERAL IRI) + | ^(SHORTCONST constshort) + | TOP + ; + +constshort + : IRI + | LITERAL + | NUMBER + | LOCAL + ; diff --git a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/ExternalFlattener.g b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/ExternalFlattener.g index 835415d0..ea95364b 100644 --- a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/ExternalFlattener.g +++ b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/ExternalFlattener.g @@ -222,7 +222,8 @@ external ; psoa - : ^(PSOA term[false]? ^(INSTANCE term[false]) tuple* slot*) + : ^(OIDLESSEMBATOM ^(INSTANCE term[false]) tuple* slot*) + | ^(PSOA term[false]? ^(INSTANCE term[false]) tuple* slot*) ; tuple diff --git a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Objectifier.g b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Objectifier.g index cfa8e862..5209a960 100644 --- a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Objectifier.g +++ b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Objectifier.g @@ -230,7 +230,8 @@ psoa[boolean isAtomic] CommonTree varNode; boolean hasSlot = false; } - : ^(PSOA oid=term? + : ^(OIDLESSEMBATOM ^(INSTANCE term) tuple* slot*) + | ^(PSOA oid=term? ^(INSTANCE type=term) tuple* (slot { hasSlot = true; })* { // If predicate variable of atom can be bound to a relational predicate, static/dynamic may be incomplete diff --git a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/QueryRewriter.g b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/QueryRewriter.g index 9825243c..2968665a 100644 --- a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/QueryRewriter.g +++ b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/QueryRewriter.g @@ -297,7 +297,8 @@ psoa[boolean isAtomicFormula] PredicateInfo pi = null; CommonTree oidTree = null; } - : ^(PSOA (oid=term { oidTree = $oid.tree; })? + : ^(OIDLESSEMBATOM ^(INSTANCE term) tuple* slot*) + | ^(PSOA (oid=term { oidTree = $oid.tree; })? ^(INSTANCE type=term { /* @@ -324,7 +325,7 @@ psoa[boolean isAtomicFormula] || $type.tree.getType() == VAR_ID // Predicate variable }? ^(PSOA $oid? ^(INSTANCE $type) tuple* slot*) -> { pi == null || // Predicate does not exist in KB - (oid != null && !oid.isVariable) || // Psoa term with a non-variable OID + (oid != null && !($oid.isVariable)) || // Psoa term with a non-variable OID (pi.isRelational() && hasIndepTuple($tuples)) || // Relational predicate having independent tuple $slots != null // Psoa term with slots }? FALSITY diff --git a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Renamer.g b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Renamer.g index c9bbc18a..692008dd 100644 --- a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Renamer.g +++ b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Renamer.g @@ -139,7 +139,8 @@ external ; psoa - : ^(PSOA term? ^(INSTANCE term) tuple* slot*) + : ^(OIDLESSEMBATOM ^(INSTANCE term) tuple* slot*) + | ^(PSOA term? ^(INSTANCE term) tuple* slot*) ; tuple diff --git a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Skolemizer.g b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Skolemizer.g index ce09ca44..1c3919ff 100644 --- a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Skolemizer.g +++ b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Skolemizer.g @@ -184,7 +184,8 @@ external ; psoa - : ^(PSOA term? ^(INSTANCE term) tuple* slot*) + : ^(OIDLESSEMBATOM ^(INSTANCE term) tuple* slot*) + | ^(PSOA term? ^(INSTANCE term) tuple* slot*) ; tuple diff --git a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/SubclassRewriter.g b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/SubclassRewriter.g index 7377e219..6e4410a7 100644 --- a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/SubclassRewriter.g +++ b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/SubclassRewriter.g @@ -113,7 +113,8 @@ external ; psoa - : ^(PSOA term? ^(INSTANCE term) tuple* slot*) + : ^(OIDLESSEMBATOM ^(INSTANCE term) tuple* slot*) + | ^(PSOA term? ^(INSTANCE term) tuple* slot*) ; tuple diff --git a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Unnester.g b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Unnester.g index 62300d57..3589c901 100644 --- a/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Unnester.g +++ b/PSOACore/src/main/antlr3/org/ruleml/psoa/transformer/Unnester.g @@ -259,7 +259,8 @@ psoa[boolean isTopLevel] $atomic::atoms.add(trim); } } - : ^(PSOA oid=term? ^(INSTANCE type=term) tuples+=tuple* slots+=slot*) + : ^(OIDLESSEMBATOM ^(INSTANCE term) tuple* slot*) + | ^(PSOA oid=term? ^(INSTANCE type=term) tuples+=tuple* slots+=slot*) // Keep the psoa term unchanged if it is oidless or on the top level -> { oid == null || isTopLevel }? ^(PSOA $oid? ^(INSTANCE $type) tuple* slot*) // Leave behind the OID otherwise diff --git a/PSOACore/src/main/java/org/ruleml/psoa/PSOAKB.java b/PSOACore/src/main/java/org/ruleml/psoa/PSOAKB.java index 128032a3..a3bb51d5 100644 --- a/PSOACore/src/main/java/org/ruleml/psoa/PSOAKB.java +++ b/PSOACore/src/main/java/org/ruleml/psoa/PSOAKB.java @@ -13,10 +13,10 @@ import org.ruleml.psoa.utils.ANTLRTreeStreamConsumer; import org.ruleml.psoa.x2psoa.*; -/** +/** * Class for storing PSOA KB information and performing KB transformations * using ANTLR tree walkers. - * + * * */ public class PSOAKB extends PSOAInput { @@ -251,6 +251,15 @@ public PSOAKB objectify(boolean differentiated, boolean dynamic) }); } + public PSOAKB embeddedObjectify() + { + return transform("embedded objectification", stream -> { + EmbeddedObjectifier objectifier = new EmbeddedObjectifier(stream); + objectifier.setExcludedLocalConstNames(m_localConsts); + + return objectifier.document(); + }); + } public PSOAKB rewriteSubclass() { @@ -347,7 +356,9 @@ public PSOAKB FOLnormalize(RelationalTransformerConfig config) { m_printStream.println("After parsing:"); printTree(); } + return schemalessChecking(config.forallWrap). + embeddedObjectify(). unnest(). rewriteSubclass(). objectify(config.differentiateObj, config.dynamicObj). diff --git a/PSOACore/src/main/java/org/ruleml/psoa/PSOAQuery.java b/PSOACore/src/main/java/org/ruleml/psoa/PSOAQuery.java index 4541c011..a1ca7a5d 100644 --- a/PSOACore/src/main/java/org/ruleml/psoa/PSOAQuery.java +++ b/PSOACore/src/main/java/org/ruleml/psoa/PSOAQuery.java @@ -4,6 +4,8 @@ * */ package org.ruleml.psoa; +import java.util.Set; + import org.antlr.runtime.ParserRuleReturnScope; import org.antlr.runtime.RecognitionException; import org.antlr.runtime.tree.Tree; @@ -15,6 +17,11 @@ public class PSOAQuery extends PSOAInput { private PSOAKB m_kb; + /** + * the set of local constants + * */ + private Set m_localConsts; + // public PSOAQuery() { // m_kb = null; // } @@ -25,7 +32,9 @@ public PSOAQuery(PSOAKB kb) { @Override protected ParserRuleReturnScope parse(PSOAPSParser parser) throws RecognitionException { - return parser.query(m_kb.getNamespaceTable()); + ParserRuleReturnScope ret = parser.query(m_kb.getNamespaceTable()); + m_localConsts = parser.getLocalConsts(); + return ret; } public PSOAQuery rename() @@ -38,6 +47,15 @@ public PSOAQuery unnest() return transform("unnesting", stream -> (new Unnester(stream)).query()); } + public PSOAQuery embeddedObjectify() + { + return transform("embedded objectification", stream -> { + EmbeddedObjectifier objectifier = new EmbeddedObjectifier(stream); + objectifier.setExcludedLocalConstNames(m_localConsts); + return objectifier.query(); + }); + } + public PSOAQuery objectify(boolean differentiated, boolean dynamic) { PSOAQuery q; @@ -115,7 +133,8 @@ public PSOAQuery FOLnormalize(RelationalTransformerConfig config) { m_printStream.println("After parsing:"); printTree(); } - return unnest(). + return embeddedObjectify(). + unnest(). objectify(config.differentiateObj, config.dynamicObj). describute(config.omitMemtermInNegativeAtoms); } diff --git a/PSOATransRun/SWI-Prolog-tests/SWI-compatible/test/recursive_frame_rule/recursive_frame_rule-KB.psoa b/PSOATransRun/SWI-Prolog-tests/SWI-compatible/test/recursive_frame_rule/recursive_frame_rule-KB.psoa index 27aeb3b9..50ab2226 100644 --- a/PSOATransRun/SWI-Prolog-tests/SWI-compatible/test/recursive_frame_rule/recursive_frame_rule-KB.psoa +++ b/PSOATransRun/SWI-Prolog-tests/SWI-compatible/test/recursive_frame_rule/recursive_frame_rule-KB.psoa @@ -1,15 +1,15 @@ Document ( Group ( Forall ?X ?Y ( - ?X # _person(_descendent->?Y) :- ?X # _person(_child->?Y) + ?X#_person(_descendent->?Y) :- ?X#_person(_child->?Y) ) Forall ?X ?Y ?Z ( - ?X # _person(_descendent->?Z) :- - And(?X # _person(_child->?Y) ?Y # _person(_descendent->?Z)) + ?X#_person(_descendent->?Z) :- + And(?X#_person(_child->?Y) ?Y#_person(_descendent->?Z)) ) - _Tom # _person(_male _child->_Amy _job->_professor) - _Eva # _person(_female _child->_Amy) - _Amy # _person([_female] [_bcs _mcs _phd] _child->_Fred) - _Fred # _person(_school->_UNB) + _Tom#_person(_male _child->_Amy _job->_professor) + _Eva#_person(_female _child->_Amy) + _Amy#_person([_female] [_bcs _mcs _phd] _child->_Fred) + _Fred#_person(_school->_UNB) ) ) \ No newline at end of file diff --git a/PSOATransRun/SWI-Prolog-tests/SWI-compatible/test/recursive_frame_rule/recursive_frame_rule-query1.psoa b/PSOATransRun/SWI-Prolog-tests/SWI-compatible/test/recursive_frame_rule/recursive_frame_rule-query1.psoa index 9d2a2e2a..f869da19 100644 --- a/PSOATransRun/SWI-Prolog-tests/SWI-compatible/test/recursive_frame_rule/recursive_frame_rule-query1.psoa +++ b/PSOATransRun/SWI-Prolog-tests/SWI-compatible/test/recursive_frame_rule/recursive_frame_rule-query1.psoa @@ -1 +1 @@ -?Ancestor # _person(_descendent->?Who) \ No newline at end of file +?Ancestor#_person(_descendent->?Who) \ No newline at end of file diff --git a/PSOATransRun/SWI-Prolog-tests/SWI-compatible/test/recursive_frame_rule/recursive_frame_rule-query2.psoa b/PSOATransRun/SWI-Prolog-tests/SWI-compatible/test/recursive_frame_rule/recursive_frame_rule-query2.psoa index 3b3a7cb5..308d225e 100644 --- a/PSOATransRun/SWI-Prolog-tests/SWI-compatible/test/recursive_frame_rule/recursive_frame_rule-query2.psoa +++ b/PSOATransRun/SWI-Prolog-tests/SWI-compatible/test/recursive_frame_rule/recursive_frame_rule-query2.psoa @@ -1,2 +1,2 @@ -And (?Ancestor1 # _person(_male _descendent->_Fred) - ?Ancestor2 # _person(_female _descendent->_Fred)) \ No newline at end of file +And (?Ancestor1#_person(_male _descendent->_Fred) + ?Ancestor2#_person(_female _descendent->_Fred)) \ No newline at end of file diff --git a/PSOATransRun/SWI-Prolog-tests/SWI-compatible/test/recursive_frame_rule/recursive_frame_rule-query3.psoa b/PSOATransRun/SWI-Prolog-tests/SWI-compatible/test/recursive_frame_rule/recursive_frame_rule-query3.psoa index ae0096c1..62d50ec5 100644 --- a/PSOATransRun/SWI-Prolog-tests/SWI-compatible/test/recursive_frame_rule/recursive_frame_rule-query3.psoa +++ b/PSOATransRun/SWI-Prolog-tests/SWI-compatible/test/recursive_frame_rule/recursive_frame_rule-query3.psoa @@ -1,2 +1,2 @@ -And (?Ancestor1 # _person(_male _descendent->?Who) - ?Ancestor2 # _person(_female _descendent->?Who)) \ No newline at end of file +And (?Ancestor1#_person(_male _descendent->?Who) + ?Ancestor2#_person(_female _descendent->?Who)) \ No newline at end of file diff --git a/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-KB.psoa b/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-KB.psoa new file mode 100644 index 00000000..27aeb3b9 --- /dev/null +++ b/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-KB.psoa @@ -0,0 +1,15 @@ +Document ( + Group ( + Forall ?X ?Y ( + ?X # _person(_descendent->?Y) :- ?X # _person(_child->?Y) + ) + Forall ?X ?Y ?Z ( + ?X # _person(_descendent->?Z) :- + And(?X # _person(_child->?Y) ?Y # _person(_descendent->?Z)) + ) + _Tom # _person(_male _child->_Amy _job->_professor) + _Eva # _person(_female _child->_Amy) + _Amy # _person([_female] [_bcs _mcs _phd] _child->_Fred) + _Fred # _person(_school->_UNB) + ) +) \ No newline at end of file diff --git a/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-answer1.psoa b/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-answer1.psoa new file mode 100644 index 00000000..6e81e0f3 --- /dev/null +++ b/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-answer1.psoa @@ -0,0 +1,5 @@ +?Ancestor=_Amy ?Who=_Fred +?Ancestor=_Eva ?Who=_Amy +?Ancestor=_Tom ?Who=_Amy +?Ancestor=_Eva ?Who=_Fred +?Ancestor=_Tom ?Who=_Fred \ No newline at end of file diff --git a/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-answer2.psoa b/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-answer2.psoa new file mode 100644 index 00000000..7c32e56d --- /dev/null +++ b/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-answer2.psoa @@ -0,0 +1,2 @@ +?Ancestor1=_Tom ?Ancestor2=_Eva +?Ancestor1=_Tom ?Ancestor2=_Amy \ No newline at end of file diff --git a/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-answer3.psoa b/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-answer3.psoa new file mode 100644 index 00000000..5d7c5b62 --- /dev/null +++ b/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-answer3.psoa @@ -0,0 +1,3 @@ +?Ancestor1=_Tom ?Ancestor2=_Eva ?Who=_Amy +?Ancestor1=_Tom ?Ancestor2=_Eva ?Who=_Fred +?Ancestor1=_Tom ?Ancestor2=_Amy ?Who=_Fred \ No newline at end of file diff --git a/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-query1.psoa b/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-query1.psoa new file mode 100644 index 00000000..9d2a2e2a --- /dev/null +++ b/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-query1.psoa @@ -0,0 +1 @@ +?Ancestor # _person(_descendent->?Who) \ No newline at end of file diff --git a/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-query2.psoa b/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-query2.psoa new file mode 100644 index 00000000..3b3a7cb5 --- /dev/null +++ b/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-query2.psoa @@ -0,0 +1,2 @@ +And (?Ancestor1 # _person(_male _descendent->_Fred) + ?Ancestor2 # _person(_female _descendent->_Fred)) \ No newline at end of file diff --git a/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-query3.psoa b/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-query3.psoa new file mode 100644 index 00000000..ae0096c1 --- /dev/null +++ b/PSOATransRun/test-DEPRECATED/recursive_frame_rule/recursive_frame_rule-query3.psoa @@ -0,0 +1,2 @@ +And (?Ancestor1 # _person(_male _descendent->?Who) + ?Ancestor2 # _person(_female _descendent->?Who)) \ No newline at end of file diff --git a/PSOATransRun/test-basic/embobj/ex_0/embobj_ex_0-KB.psoa b/PSOATransRun/test-basic/embobj/ex_0/embobj_ex_0-KB.psoa new file mode 100644 index 00000000..0a95ea56 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_0/embobj_ex_0-KB.psoa @@ -0,0 +1,85 @@ +RuleML ( + Assert ( + + /* + Embedded oidful atoms are paired with (otherwise identical) embedded oidless atoms undergoing embobj, + showing that subsequent unnest etc. creates equivalent (identical up to renamed local constants) results + */ + + + p1(o1#q()) + + p2(#q()) + + /* + > p1(?o#q()) + Answer(s): + ?o=_o1 + + > p2(?o#q()) + Answer(s): + ?o=_1 + */ + + + p3(-[o2#q() o3#r()]) + + p4(-[#q() #r()]) + + /* + > p3(-[?o2#q() ?o3#r()]) + Answer(s): + ?o2=_o2 ?o3=_o3 + + > p4(-[?o2#q() ?o3#r()]) + Answer(s): + ?o2=_2 ?o3=_3 + */ + + + p5(o4#s->filler) + + p6(#s->filler) + + /* + > p5(?o4#s->filler) + Answer(s): + ?o4=_o4 + + > p6(?o4#s->filler) + Answer(s): + ?o4=_4 + */ + + + p7(slot->o5#f) + + p8(slot->#f) + + /* + > p7(slot->?o5#f) + Answer(s): + ?o5=_o5 + + > p8(slot->?o5#f) + Answer(s): + ?o5=_5 + */ + + + o6#q()#p9() + + #q()#p10() + + /* + > ?o6#q()#p9() + Answer(s): + ?o6=_o6 + + > ?o6#q()#p10() + Answer(s): + ?o6=_6 + */ + + ) +) diff --git a/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-KB.psoa b/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-KB.psoa new file mode 100644 index 00000000..21dd828f --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-KB.psoa @@ -0,0 +1,62 @@ +RuleML( + Assert( + + % This oidful atom contains both oidful and oidless embedded atoms: + % o#c is oidful-embedded in the OID position + % #f(a) is oidless-embedded in the first argument position of the top-level tuple + % #h(-[a b]) is oidless-embedded in the second argument position of the top-level tuple + % oid#g(a b) is oidful-embedded in the third argument position of the top-level tuple + % The oidless-embedded atoms will be embeddedly objectified. + % Then all embedded atoms will be oidful and unnested. + + o#c#d(#f(a) #h(-[a b]) oid#g(a b)) + + /* OID-embedded atoms like o#c of oidful top-level atoms like o#c#d(...) + of this form are unnested in the host KB as follows: + + o#c + o#d(#f(a) #h(-[a b]) oid#g(a b)) + + */ + + % This oidless atom just omits the o of the above atom: + % #c is oidless-embedded in the OID position + % This oidless-embedded atoms will also be embeddedly objectified. + % The rest is as above. + + #c#d(#f(a) #h(-[a b]) oid#g(a b)) + + #p(f1(#p1(#p2(a u->v))) + s->g1(#q1(g2(#q2(g3(b c)))))) + + % Use a single level of objectification, initially. + #d(#f(a) #h(-[a b]) oid2#g(a b)) + + % two levels of embedded objectification. + #d2(#f(a #i(a b)) #h(-[a b]) oid3#g(a b)) + + % three levels of embedded objectification. + #d3(#f(a #i(a b #j(c))) #h(-[a b]) oid4#g(a b #k(m n))) + + #purchase(John #store(possession->asset(Mary) location->place(TimesSquare NYC)) Fido) + + % embedded atom in condition. + f(oid5#g(a b)) + f(b) :- f(#g(a b)) + + % embedded atom in conclusion. + g(#g(a b)) :- f(b) + + % embedded atoms in both conclusion and condition. + #d4(#f(a) #h(-[a b]) oid5#g(a b)) :- + d4(#f(a #i(a b #j(c))) #h(-[a b]) oid6#g(a b #k(m n))) + + /* + + > o#d(?o1#f(a) ?o2#h(-[a b]) #g(a b)) + ?o1=_1 ?o2=_2 + + */ + + ) +) diff --git a/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-answer1.psoa b/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-answer1.psoa new file mode 100644 index 00000000..7cfab5b0 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-answer1.psoa @@ -0,0 +1 @@ +yes diff --git a/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-answer2.psoa b/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-answer2.psoa new file mode 100644 index 00000000..7cfab5b0 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-answer2.psoa @@ -0,0 +1 @@ +yes diff --git a/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-answer3.psoa b/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-answer3.psoa new file mode 100644 index 00000000..8a3bdc7a --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-answer3.psoa @@ -0,0 +1,4 @@ +?B=_a +?B=_a +?B=_oid5 +?B=_b diff --git a/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-query1.psoa b/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-query1.psoa new file mode 100644 index 00000000..700bb7fb --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-query1.psoa @@ -0,0 +1 @@ +o#c diff --git a/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-query2.psoa b/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-query2.psoa new file mode 100644 index 00000000..f0339952 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-query2.psoa @@ -0,0 +1 @@ +o#d(#f(a) #h(-[a b]) oid#g(a b)) diff --git a/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-query3.psoa b/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-query3.psoa new file mode 100644 index 00000000..ec90bc19 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_1/embobj_ex_1-query3.psoa @@ -0,0 +1 @@ +f(?B) diff --git a/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-KB.psoa b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-KB.psoa new file mode 100644 index 00000000..71441961 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-KB.psoa @@ -0,0 +1,44 @@ +RuleML( + Assert( + + p2(#g(b a)) + + p3(#f(a)) :- p2(#g(b a)) + + Forall ?A ( + p4(#f(a)) :- p2(#g(b ?A)) + ) + + Forall ?Var ( + p5(#f(a) ?Var) :- p2(#g(b a)) + ) + + transaction200#purchase( + buyer->John + seller->#store(possession->asset(Mary) location->place(TimesSquare NYC)) + item->Fido) + + + Forall ?b ?s ?i ?t ( + #responsiPred(?t)#liability(bearer->?b item->?i) :- + ?t#purchase(buyer->?b seller->?s item->?i) + ) + + /* + + > p3(?o#f(a)) + ?o=_skolem1(_3) + + > p3(?o#f(?a)) + ?o=_skolem1(_3) ?a=_a + + > transaction200#purchase(seller->?o#?s) + ?o=_2 ?s=_store + + > ?o#responsiPred(?t) + ?o=_skolem7(_John _2 _Fido _transaction200) ?t=_transaction200 + + */ + + ) +) diff --git a/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-answer1.psoa b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-answer1.psoa new file mode 100644 index 00000000..7ecb56eb --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-answer1.psoa @@ -0,0 +1 @@ +no diff --git a/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-answer2.psoa b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-answer2.psoa new file mode 100644 index 00000000..7cfab5b0 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-answer2.psoa @@ -0,0 +1 @@ +yes diff --git a/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-answer3.psoa b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-answer3.psoa new file mode 100644 index 00000000..2d6df4a6 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-answer3.psoa @@ -0,0 +1 @@ +?V=Var0 diff --git a/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-answer4.psoa b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-answer4.psoa new file mode 100644 index 00000000..5c4e913b --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-answer4.psoa @@ -0,0 +1 @@ +?t=_transaction200 diff --git a/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-answer5.psoa b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-answer5.psoa new file mode 100644 index 00000000..5c4e913b --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-answer5.psoa @@ -0,0 +1 @@ +?t=_transaction200 diff --git a/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-answer6.psoa b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-answer6.psoa new file mode 100644 index 00000000..455cbfcd --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-answer6.psoa @@ -0,0 +1 @@ +?t=_transaction200 ?b=_John ?i=_Fido diff --git a/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-query1.psoa b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-query1.psoa new file mode 100644 index 00000000..25756a53 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-query1.psoa @@ -0,0 +1 @@ +p3(o#f(?a)) diff --git a/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-query2.psoa b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-query2.psoa new file mode 100644 index 00000000..dabb01bb --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-query2.psoa @@ -0,0 +1 @@ +p4(#f(a)) diff --git a/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-query3.psoa b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-query3.psoa new file mode 100644 index 00000000..306a85ff --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-query3.psoa @@ -0,0 +1 @@ +p5(#f(a) ?V) diff --git a/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-query4.psoa b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-query4.psoa new file mode 100644 index 00000000..411005ab --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-query4.psoa @@ -0,0 +1 @@ +#responsiPred(?t) diff --git a/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-query5.psoa b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-query5.psoa new file mode 100644 index 00000000..667380ff --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-query5.psoa @@ -0,0 +1 @@ +#responsiPred(?t)#liability diff --git a/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-query6.psoa b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-query6.psoa new file mode 100644 index 00000000..073d9383 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_2/embobj_ex_2-query6.psoa @@ -0,0 +1 @@ +#responsiPred(?t)#liability(bearer->?b item->?i) diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-KB.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-KB.psoa new file mode 100644 index 00000000..a869bcc1 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-KB.psoa @@ -0,0 +1,108 @@ +RuleML( + Assert( + + /* + Descriptor-embedded atoms + */ + + p1(#name->a) % slot name + p2(name->#filler) % slot filler + p3(+[#dep_tup_term]) % dependent tuple term + p4(-[#indep_tup_term]) % independent tuple term + p5(#imp_tup_term) % implicit dependent tuple term + + p1_p2(#name->a name->#filler) % mix of p1, p2 + p1_p3(#name->a +[#dep_tup_term]) % mix of p1, p3 + p1_p4(#name->a -[#indep_tup_term]) % mix of p1, p4 + p1_p5(#imp_tup_term #name->a) % mix of p1, p5 + + p1_p2_p3(#name->a name->#filler +[#dep_tup_term]) + p1_p2_p4(#name->a name->#filler -[#indep_dup_term]) + p1_p2_p5(#imp_tup_term #name->a name->#filler) + p2_p3_p4(#name->a name->#filler -[#indep_dup_term]) + p2_p3_p5(#imp_tup_term name->#filler) + p3_p4_p5(+[#imp_tup_term #dep_tup_term] -[#indep_tup_term]) + + % with vars, other attached data. + Forall ?C ( + v1(#atom(a b ?C)) + ) + Forall ?A ?C ( + v2(#atom(?A b ?C)->filler) + ) + Forall ?C ( + v3(name->#atom(a b ?C name->filler)) + ) + Forall ?C ( + v4(+[#dep_tup_term(?C)]) + ) + + + /* + OID-embedded atom + */ + + #p()#q() % empty bags of descriptors + + /* + OID-embedded atoms with descriptor-embedded atoms + */ + + #p1(#name->a)#q() % slot name + #p2(name->#filler)#q() % slot filler + #p3(+[#dep_tup_term])#q() % dependent tuple term + #p4(-[#indep_tup_term])#q() % independent tuple term + #p5(#imp_tup_term)#q() % implicit dependent tuple term + + #p1_p2(#name->a name->#filler)#q() % mix of p1, p2 + #p1_p3(#name->a +[#dep_tup_term])#q() % mix of p1, p3 + #p1_p4(#name->a -[#indep_tup_term])#q() % mix of p1, p4 + #p1_p5(#imp_tup_term #name->a)#q() % mix of p1, p5 + + #p1_p2_p3(#name->a name->#filler +[#dep_tup_term])#q() + #p1_p2_p4(#name->a name->#filler -[#indep_dup_term])#q() + #p1_p2_p5(#imp_tup_term #name->a name->#filler)#q() + #p2_p3_p4(#name->a name->#filler -[#indep_dup_term])#q() + #p2_p3_p5(#imp_tup_term name->#filler)#q() + #p3_p4_p5(+[#imp_tup_term #dep_tup_term] -[#indep_tup_term])#q() + + /* + + > ?o#p1(#name->a)#q(#name->a) + ?o=_33 + + > ?o#p2 + ?o=_35 + ?o=_78 + + > ?o#p2(name->?f) + ?o=_35 ?f=_34 + ?o=_78 ?f=_2 + + > ?o#p2(name->?o2#filler) + ?o2=_34 ?o=_35 + ?o2=_2 ?o=_78 + + > v1(?o#atom(a b ?C)) + ?o=_skolem1(Var1) ?C=Var1 + + > v2(?Atom#atom(a b c)->filler) + ?Atom=_skolem3(_a _c) + + > v2(?Atom#atom(a ?B c)->filler) + ?Atom=_skolem3(_a _c) ?B=_b + + > v2(?Atom#atom(?A b ?C)->filler) + ?Atom=_skolem3(Var2 Var3) ?A=Var2 ?C=Var3 + + > v3(name->?filler#atom) + ?filler=_skolem5(Var0) + + > p1_p2_p5(?o1#imp_tup_term ?o2#name->a name->?o3#filler) + ?o1=_20 ?o2=_21 ?o3=_22 + ?o1=_62 ?o2=_63 ?o3=_64 + + */ + + ) +) diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer1.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer1.psoa new file mode 100644 index 00000000..7cfab5b0 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer1.psoa @@ -0,0 +1 @@ +yes diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer10.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer10.psoa new file mode 100644 index 00000000..7ecb56eb --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer10.psoa @@ -0,0 +1 @@ +no diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer11.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer11.psoa new file mode 100644 index 00000000..7cfab5b0 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer11.psoa @@ -0,0 +1 @@ +yes diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer12.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer12.psoa new file mode 100644 index 00000000..6e8ae3e3 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer12.psoa @@ -0,0 +1 @@ +?filler=_filler diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer2.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer2.psoa new file mode 100644 index 00000000..7cfab5b0 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer2.psoa @@ -0,0 +1 @@ +yes diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer3.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer3.psoa new file mode 100644 index 00000000..7cfab5b0 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer3.psoa @@ -0,0 +1 @@ +yes diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer4.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer4.psoa new file mode 100644 index 00000000..7cfab5b0 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer4.psoa @@ -0,0 +1 @@ +yes diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer5.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer5.psoa new file mode 100644 index 00000000..7cfab5b0 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer5.psoa @@ -0,0 +1 @@ +yes diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer6.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer6.psoa new file mode 100644 index 00000000..7cfab5b0 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer6.psoa @@ -0,0 +1 @@ +yes diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer7.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer7.psoa new file mode 100644 index 00000000..7cfab5b0 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer7.psoa @@ -0,0 +1 @@ +yes diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer8.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer8.psoa new file mode 100644 index 00000000..7cfab5b0 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer8.psoa @@ -0,0 +1 @@ +yes diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer9.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer9.psoa new file mode 100644 index 00000000..7cfab5b0 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-answer9.psoa @@ -0,0 +1 @@ +yes diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query1.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query1.psoa new file mode 100644 index 00000000..31a7080b --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query1.psoa @@ -0,0 +1 @@ +#p()#q diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query10.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query10.psoa new file mode 100644 index 00000000..8c896f50 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query10.psoa @@ -0,0 +1 @@ +#p1(#name) diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query11.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query11.psoa new file mode 100644 index 00000000..8a215ecf --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query11.psoa @@ -0,0 +1 @@ +v3(name->#atom) diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query12.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query12.psoa new file mode 100644 index 00000000..fc352562 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query12.psoa @@ -0,0 +1 @@ +v3(name->#atom(a b c name->?filler)) diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query2.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query2.psoa new file mode 100644 index 00000000..5690298b --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query2.psoa @@ -0,0 +1 @@ +#p#q() diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query3.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query3.psoa new file mode 100644 index 00000000..31a7080b --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query3.psoa @@ -0,0 +1 @@ +#p()#q diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query4.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query4.psoa new file mode 100644 index 00000000..a5c22df5 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query4.psoa @@ -0,0 +1 @@ +#p#q diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query5.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query5.psoa new file mode 100644 index 00000000..b754c5d3 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query5.psoa @@ -0,0 +1 @@ +#p1(#name->a) diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query6.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query6.psoa new file mode 100644 index 00000000..c0fe316c --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query6.psoa @@ -0,0 +1 @@ +#p1(#name->a)#q diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query7.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query7.psoa new file mode 100644 index 00000000..36393043 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query7.psoa @@ -0,0 +1 @@ +#p1(#name->a)#q() diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query8.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query8.psoa new file mode 100644 index 00000000..f8c52a66 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query8.psoa @@ -0,0 +1 @@ +#p1(#name->a)#q(#name->a) diff --git a/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query9.psoa b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query9.psoa new file mode 100644 index 00000000..14e187d2 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/ex_3/embobj_ex_3-query9.psoa @@ -0,0 +1 @@ +#p1 diff --git a/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-KB.psoa b/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-KB.psoa new file mode 100644 index 00000000..9dc08f53 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-KB.psoa @@ -0,0 +1,82 @@ +RuleML( + Assert( + +/* +Atom as a user-specified (but itself oidless) OID of an atom 'refining' it +========================================================================== + +Consider the atom + +transaction200#purchase( + buyer->John + seller->#store(possession->asset(Mary) + location->place(TimesSquare NYC)) + item->Fido) + +"store" is embedded into the purchase predicate and is preceded by a +hash prefix operator. + +Behind the scenes, an object is created as a member +of the "store" predicate, with the listed slot-filler pairs. + +The object becomes itself the filler of transaction200's "seller" +slot. + +By nesting atoms -- even allowing embedded OID atoms -- it is possible +to specify multiple memberships pertaining to the same anonymous +object. + +Suppose the store in Times Square belonged to the Macy's department +store chain/franchise. This could be written as + +#store(possession->asset(Mary) + location->place(TimesSquare NYC))#franchise(Macy_s) + +and situated in the transaction like so: +*/ + +transaction200#purchase( + buyer->John + seller->#store(possession->asset(Mary) + location->place(TimesSquare NYC))#franchise(Macy_s) + item->Fido) + +/* +~~embobj~~> +transaction200#purchase( + buyer->John + seller->_1#store(possession->asset(Mary) + location->place(TimesSquare NYC))#franchise(Macy_s) + item->Fido) +~~unnest~~> +And(_1#store(possession->asset(Mary) + location->place(TimesSquare NYC))#franchise(Macy_s) + transaction200#purchase( + buyer->John + seller->_1 + item->Fido) + ) +~~unnest~~> +And(_1#store(possession->asset(Mary) + location->place(TimesSquare NYC)) + _1#franchise(Macy_s) + transaction200#purchase( + buyer->John + seller->_1 + item->Fido) + ) + +Some sample queries: + +> transaction200#purchase(seller->?s) +Answer(s): +?s=_1 + +> And(transaction200#purchase(seller->?s) ?s#store ?s#franchise(?F)) +Answer(s): +?s=_1 ?F=_Macy_s + +*/ + + ) +) diff --git a/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-answer1.psoa b/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-answer1.psoa new file mode 100644 index 00000000..5cc27492 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-answer1.psoa @@ -0,0 +1 @@ +?asset=_asset(_Mary) diff --git a/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-answer2.psoa b/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-answer2.psoa new file mode 100644 index 00000000..5a9ae934 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-answer2.psoa @@ -0,0 +1 @@ +?asset=_asset(_Mary) ?F=_Macy_s diff --git a/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-answer3.psoa b/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-answer3.psoa new file mode 100644 index 00000000..5a9ae934 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-answer3.psoa @@ -0,0 +1 @@ +?asset=_asset(_Mary) ?F=_Macy_s diff --git a/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-query1.psoa b/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-query1.psoa new file mode 100644 index 00000000..986d939f --- /dev/null +++ b/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-query1.psoa @@ -0,0 +1 @@ +transaction200#purchase(seller->#store(possession->?asset)) diff --git a/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-query2.psoa b/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-query2.psoa new file mode 100644 index 00000000..77cdfab3 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-query2.psoa @@ -0,0 +1 @@ +transaction200#purchase(seller->#store(possession->?asset)#franchise(?F)) diff --git a/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-query3.psoa b/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-query3.psoa new file mode 100644 index 00000000..84e6e160 --- /dev/null +++ b/PSOATransRun/test-basic/embobj/store_franchise/store_franchise-query3.psoa @@ -0,0 +1 @@ +transaction200#purchase(seller->#franchise(?F)#store(possession->?asset)) diff --git a/PSOATransRun/test/recursive_frame_rule/recursive_frame_rule-KB.psoa b/PSOATransRun/test/recursive_frame_rule/recursive_frame_rule-KB.psoa index 27aeb3b9..50ab2226 100644 --- a/PSOATransRun/test/recursive_frame_rule/recursive_frame_rule-KB.psoa +++ b/PSOATransRun/test/recursive_frame_rule/recursive_frame_rule-KB.psoa @@ -1,15 +1,15 @@ Document ( Group ( Forall ?X ?Y ( - ?X # _person(_descendent->?Y) :- ?X # _person(_child->?Y) + ?X#_person(_descendent->?Y) :- ?X#_person(_child->?Y) ) Forall ?X ?Y ?Z ( - ?X # _person(_descendent->?Z) :- - And(?X # _person(_child->?Y) ?Y # _person(_descendent->?Z)) + ?X#_person(_descendent->?Z) :- + And(?X#_person(_child->?Y) ?Y#_person(_descendent->?Z)) ) - _Tom # _person(_male _child->_Amy _job->_professor) - _Eva # _person(_female _child->_Amy) - _Amy # _person([_female] [_bcs _mcs _phd] _child->_Fred) - _Fred # _person(_school->_UNB) + _Tom#_person(_male _child->_Amy _job->_professor) + _Eva#_person(_female _child->_Amy) + _Amy#_person([_female] [_bcs _mcs _phd] _child->_Fred) + _Fred#_person(_school->_UNB) ) ) \ No newline at end of file diff --git a/PSOATransRun/test/recursive_frame_rule/recursive_frame_rule-query1.psoa b/PSOATransRun/test/recursive_frame_rule/recursive_frame_rule-query1.psoa index 9d2a2e2a..f869da19 100644 --- a/PSOATransRun/test/recursive_frame_rule/recursive_frame_rule-query1.psoa +++ b/PSOATransRun/test/recursive_frame_rule/recursive_frame_rule-query1.psoa @@ -1 +1 @@ -?Ancestor # _person(_descendent->?Who) \ No newline at end of file +?Ancestor#_person(_descendent->?Who) \ No newline at end of file diff --git a/PSOATransRun/test/recursive_frame_rule/recursive_frame_rule-query2.psoa b/PSOATransRun/test/recursive_frame_rule/recursive_frame_rule-query2.psoa index 3b3a7cb5..308d225e 100644 --- a/PSOATransRun/test/recursive_frame_rule/recursive_frame_rule-query2.psoa +++ b/PSOATransRun/test/recursive_frame_rule/recursive_frame_rule-query2.psoa @@ -1,2 +1,2 @@ -And (?Ancestor1 # _person(_male _descendent->_Fred) - ?Ancestor2 # _person(_female _descendent->_Fred)) \ No newline at end of file +And (?Ancestor1#_person(_male _descendent->_Fred) + ?Ancestor2#_person(_female _descendent->_Fred)) \ No newline at end of file diff --git a/PSOATransRun/test/recursive_frame_rule/recursive_frame_rule-query3.psoa b/PSOATransRun/test/recursive_frame_rule/recursive_frame_rule-query3.psoa index ae0096c1..62d50ec5 100644 --- a/PSOATransRun/test/recursive_frame_rule/recursive_frame_rule-query3.psoa +++ b/PSOATransRun/test/recursive_frame_rule/recursive_frame_rule-query3.psoa @@ -1,2 +1,2 @@ -And (?Ancestor1 # _person(_male _descendent->?Who) - ?Ancestor2 # _person(_female _descendent->?Who)) \ No newline at end of file +And (?Ancestor1#_person(_male _descendent->?Who) + ?Ancestor2#_person(_female _descendent->?Who)) \ No newline at end of file