1
1
mirror of https://github.com/github/semantic.git synced 2024-12-21 05:41:54 +03:00

Take surrounding context into account when computing bases.

```
1 `div` 2 = 0
2 `div` 2 = 1
3 `div` 2 = 1
```

etc.

This means that given _q_ = 3, the base for b in [a, b, c, d] will be
[a, b, c] instead of [b, c, d]. This means that grams encode limited
sibling ordering information both forwards and backwards, making them
slightly more stable.
This commit is contained in:
Rob Rix 2016-08-18 11:14:37 -04:00
parent c3e0e9e7d4
commit d17f76bc60

View File

@ -91,7 +91,7 @@ pqGramDecorator getLabel p q = cata algebra
where algebra term = let label = getLabel term in
cofree ((gram label .: headF term) :< assignParentAndSiblingLabels (tailF term) label)
gram label = Gram (padToSize p []) (padToSize q (pure (Just label)))
assignParentAndSiblingLabels functor label = (`evalState` (siblingLabels functor)) (for functor (assignLabels label))
assignParentAndSiblingLabels functor label = (`evalState` (replicate (q `div` 2) Nothing <> siblingLabels functor)) (for functor (assignLabels label))
assignLabels :: label -> Cofree f (Record (Gram label ': fields)) -> State [Maybe label] (Cofree f (Record (Gram label ': fields)))
assignLabels label a = case runCofree a of
RCons gram rest :< functor -> do