Fix an highlighting bug when pattern overlap

parent e5ab7574
...@@ -208,7 +208,10 @@ highlightNgrams (NgramsTable table) input = ...@@ -208,7 +208,10 @@ highlightNgrams (NgramsTable table) input =
-- NOTE that only the first matching pattern is used, the others are ignored! -- NOTE that only the first matching pattern is used, the others are ignored!
goFold :: Partial => _ -> Tuple Int (Array Int) -> _ 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 case A.index pis 0 of
Nothing -> Nothing ->
{ i0, s, l } { i0, s, l }
......
...@@ -12,9 +12,7 @@ import Data.Map as Map ...@@ -12,9 +12,7 @@ import Data.Map as Map
import Data.Set as Set import Data.Set as Set
spec :: Spec Unit spec :: Spec Unit
spec = spec = do
describe "NgramsTable.highlightNgrams" do
it "partially works" do
let ne ngrams list = let ne ngrams list =
NgramsElement NgramsElement
{ ngrams { ngrams
...@@ -25,7 +23,9 @@ spec = ...@@ -25,7 +23,9 @@ spec =
, children: Set.empty , children: Set.empty
} }
tne ngrams list = Tuple ngrams (ne ngrams list) 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 (Map.fromFoldable [tne "graph" GraphTerm
,tne "stop" StopTerm ,tne "stop" StopTerm
,tne "candidate" CandidateTerm ,tne "candidate" CandidateTerm
...@@ -38,3 +38,28 @@ spec = ...@@ -38,3 +38,28 @@ spec =
,Tuple "s at every " Nothing ,Tuple "s at every " Nothing
,Tuple "candidate" (Just CandidateTerm)] ,Tuple "candidate" (Just CandidateTerm)]
highlightNgrams table input `shouldEqual` output 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