Commit 95f2c1a7 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[NgramsTable] fixes to sending a lowercase ngram

parent a77c292a
...@@ -15,6 +15,7 @@ import Prelude ...@@ -15,6 +15,7 @@ import Prelude
import Data.Lens ((^?), _Just) import Data.Lens ((^?), _Just)
import Data.Lens.At (at) import Data.Lens.At (at)
import Data.Maybe ( Maybe(..), maybe, maybe' ) import Data.Maybe ( Maybe(..), maybe, maybe' )
import Data.String as S
import Data.Tuple ( Tuple(..) ) import Data.Tuple ( Tuple(..) )
import Data.Tuple.Nested ( (/\) ) import Data.Tuple.Nested ( (/\) )
import DOM.Simple.Event as DE import DOM.Simple.Event as DE
...@@ -57,7 +58,7 @@ annotatedFieldComponent = R.hooksComponent "AnnotatedField" cpt ...@@ -57,7 +58,7 @@ annotatedFieldComponent = R.hooksComponent "AnnotatedField" cpt
let x = E.clientX event let x = E.clientX event
y = E.clientY event y = E.clientY event
setList t = do setList t = do
setTermList text' (Just list) t setTermList (S.toLower text') (Just list) t
setMenu Nothing setMenu Nothing
setMenu $ Just {x, y, list: Just list, menuType: SetTermListItem, setList} setMenu $ Just {x, y, list: Just list, menuType: SetTermListItem, setList}
......
...@@ -60,7 +60,6 @@ import Data.List ((:), List(Nil)) ...@@ -60,7 +60,6 @@ import Data.List ((:), List(Nil))
import Data.Map (Map) import Data.Map (Map)
import Data.Map as Map import Data.Map as Map
import Data.Maybe (Maybe(..), maybe) import Data.Maybe (Maybe(..), maybe)
import Data.String.Common (trim)
import Data.Traversable (class Traversable, traverse, traverse_, sequence) import Data.Traversable (class Traversable, traverse, traverse_, sequence)
import Data.TraversableWithIndex (class TraversableWithIndex, traverseWithIndex) import Data.TraversableWithIndex (class TraversableWithIndex, traverseWithIndex)
import Data.Set (Set) import Data.Set (Set)
...@@ -212,7 +211,7 @@ highlightNgrams (NgramsTable table) input0 = ...@@ -212,7 +211,7 @@ highlightNgrams (NgramsTable table) input0 =
map trimmer $ A.reverse (A.fromFoldable (consNonEmpty sN.s sN.l)) map trimmer $ A.reverse (A.fromFoldable (consNonEmpty sN.s sN.l))
where where
-- we need to trim so that the highlighting is without endings -- we need to trim so that the highlighting is without endings
trimmer (Tuple t (Just l)) = Tuple (trim t) (Just l) trimmer (Tuple t (Just l)) = Tuple (S.trim t) (Just l)
trimmer x = x trimmer x = x
sp x = " " <> S.replaceAll (S.Pattern " ") (S.Replacement " ") x <> " " sp x = " " <> S.replaceAll (S.Pattern " ") (S.Replacement " ") x <> " "
unsp x = unsp x =
...@@ -221,11 +220,10 @@ highlightNgrams (NgramsTable table) input0 = ...@@ -221,11 +220,10 @@ highlightNgrams (NgramsTable table) input0 =
Just x1 -> S.replaceAll (S.Pattern " ") (S.Replacement " ") (S.drop 1 x1) Just x1 -> S.replaceAll (S.Pattern " ") (S.Replacement " ") (S.drop 1 x1)
input = sp input0 input = sp input0
pats = A.fromFoldable (Map.keys table) pats = A.fromFoldable (Map.keys table)
ixs = indicesOfAny (sp <$> pats) (S.toLower $ R.replace theRegex " " input)
where
theRegex = case R.regex "[.,;:!?'\\{}()]" (R.global <> R.multiline) of theRegex = case R.regex "[.,;:!?'\\{}()]" (R.global <> R.multiline) of
Left e -> unsafePartial $ crashWith e Left e -> unsafePartial $ crashWith e
Right r -> r Right r -> r
ixs = indicesOfAny (sp <$> pats) (S.toLower $ R.replace theRegex " " input)
consNonEmpty x xs consNonEmpty x xs
| S.null x = xs | S.null x = xs
......
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