Fix an highlighting bug when pattern overlap

parent e5ab7574
......@@ -208,7 +208,10 @@ highlightNgrams (NgramsTable table) input =
-- NOTE that only the first matching pattern is used, the others are ignored!
goFold :: Partial => _ -> Tuple Int (Array Int) -> _
goFold { i0, s, l } (Tuple i pis) =
goFold { i0, s, l } (Tuple i pis)
| i < i0 =
{ i0, s, l }
| otherwise =
case A.index pis 0 of
Nothing ->
{ i0, s, l }
......
......@@ -12,9 +12,7 @@ import Data.Map as Map
import Data.Set as Set
spec :: Spec Unit
spec =
describe "NgramsTable.highlightNgrams" do
it "partially works" do
spec = do
let ne ngrams list =
NgramsElement
{ ngrams
......@@ -25,7 +23,9 @@ spec =
, children: Set.empty
}
tne ngrams list = Tuple ngrams (ne ngrams list)
table = NgramsTable
describe "NgramsTable.highlightNgrams" do
it "partially works" do
let table = NgramsTable
(Map.fromFoldable [tne "graph" GraphTerm
,tne "stop" StopTerm
,tne "candidate" CandidateTerm
......@@ -38,3 +38,28 @@ spec =
,Tuple "s at every " Nothing
,Tuple "candidate" (Just CandidateTerm)]
highlightNgrams table input `shouldEqual` output
it "works when pattern overlaps" do
let table = NgramsTable
(Map.fromFoldable [tne "is" StopTerm
,tne "a" StopTerm
,tne "of" StopTerm
,tne "new" GraphTerm
,tne "the" GraphTerm
,tne "state" GraphTerm
])
input = "SCIPION is a new state of the"
output = [Tuple "SCIPION " Nothing
,Tuple "is" (Just StopTerm)
,Tuple " " Nothing
,Tuple "a" (Just StopTerm)
,Tuple " " Nothing
,Tuple "new" (Just GraphTerm)
,Tuple " " Nothing
,Tuple "state" (Just GraphTerm)
,Tuple " " Nothing
,Tuple "of" (Just StopTerm)
,Tuple " " Nothing
,Tuple "the" (Just GraphTerm)
]
highlightNgrams table input `shouldEqual` output
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment