Safe Haskell | Safe-Infered |
---|
We use a flat semantics in GenI (bag of literals).
- data Literal gv = Literal {
- lHandle :: gv
- lPredicate :: gv
- lArgs :: [gv]
- type Sem = [Literal GeniVal]
- type LitConstr = (Literal GeniVal, [Text])
- type SemInput = (Sem, Flist GeniVal, [LitConstr])
- emptyLiteral :: Literal GeniVal
- removeConstraints :: SemInput -> SemInput
- sortSem :: Ord a => [Literal a] -> [Literal a]
- compareOnLiteral :: Ord a => Literal a -> Literal a -> Ordering
- sortByAmbiguity :: Sem -> Sem
- class HasConstants a where
- displaySemInput :: ([LitConstr] -> Text) -> SemInput -> Text
- isInternalHandle :: Text -> Bool
- subsumeSem :: Sem -> Sem -> [(Sem, Subst)]
- subsumeSemH :: Sem -> Sem -> [(Sem, Subst)]
- subsumeLiteral :: MonadUnify m => Literal GeniVal -> Literal GeniVal -> m (Literal GeniVal, Subst)
- unifySem :: Sem -> Sem -> [(Sem, Subst)]
- unifySemH :: Sem -> Sem -> [(Sem, Subst)]
- unifyLiteral :: MonadUnify m => Literal GeniVal -> Literal GeniVal -> m (Literal GeniVal, Subst)
Documentation
data Literal gv
A single semantic literal containing its handle, predicate, and arguments
This can be paramaterised on the kinds of variables it uses, for example,
GeniVal
for a semantics that you might still want to do unification on
or Text
if it's supposed to be ground.
Literal | |
|
Typeable1 Literal | |
Pretty SemInput | |
Pretty Sem | |
GeniShow SemInput | |
GeniShow LitConstr | |
GeniShow Sem | |
Eq gv => Eq (Literal gv) | |
Data gv => Data (Literal gv) | |
Ord gv => Ord (Literal gv) | |
Binary g => Binary (Literal g) | |
NFData g => NFData (Literal g) | |
Pretty (Literal GeniVal) | |
GeniShow (Literal GeniVal) | |
DescendGeniVal a => DescendGeniVal (Literal a) | |
Collectable a => Collectable (Literal a) | |
HasConstants (Literal GeniVal) |
type LitConstr = (Literal GeniVal, [Text])
A literal and any constraints associated with it (semantic input)
type SemInput = (Sem, Flist GeniVal, [LitConstr])
Semantics, index constraints, literal constraints
The intention here is that for (sem, icons, lcons)
all (
elem
sem) lcons
emptyLiteral :: Literal GeniVal
An empty literal, not sure you should really be using this
Utility functions
removeConstraints :: SemInput -> SemInput
Strip any index or literal constraints from an input. Use with care.
compareOnLiteral :: Ord a => Literal a -> Literal a -> Ordering
Default comparison for a literal
sortByAmbiguity :: Sem -> Sem
Sort primarily putting the ones with the most constants first and secondarily by the number of instances a predicate occurs (if plain string; atomic disjunction/vars treated as infinite)
class HasConstants a where
Anything that we would want to count the number constants in (as opposed to variables)
displaySemInput :: ([LitConstr] -> Text) -> SemInput -> Text
Helper for displaying or pretty printing a semantic input
This gives you a bit of control over how each literal is displayed
isInternalHandle :: Text -> Bool
Is a handle generated by GenI. GenI lets you write literals without a handle; in these cases a unique handle is generated and hidden from the UI.
Subsumption
subsumeSem :: Sem -> Sem -> [(Sem, Subst)]
x
returns all the possible ways to unify
subsumeSem
yx
with some SUBSET of y
so that x
subsumes y
.
If x
does NOT subsume y
, we return the empty list.
subsumeSemH :: Sem -> Sem -> [(Sem, Subst)]
Helper for subsumeSem
traversal
subsumeLiteral :: MonadUnify m => Literal GeniVal -> Literal GeniVal -> m (Literal GeniVal, Subst)
p1
is the unification of subsumeLiteral
p2p1
and p2
if
both literals have the same arity, and the handles, predicates,
and arguments in p1
all subsume their counterparts in p2
Unification
unifySem :: Sem -> Sem -> [(Sem, Subst)]
Return the list of minimal ways to unify two semantics, ie. where any literals that are not the product of a succesful unification really do not unify with anything else.
unifyLiteral :: MonadUnify m => Literal GeniVal -> Literal GeniVal -> m (Literal GeniVal, Subst)
Two literals unify if they have the same arity, and their handles, predicates, and arguments also unify