Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
142
Issues
142
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
purescript-gargantext
Commits
8e724e56
Unverified
Commit
8e724e56
authored
Jul 11, 2019
by
Nicolas Pouillard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor ngram normalization
parent
16138dfa
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
18 deletions
+24
-18
AnnotatedField.purs
src/Gargantext/Components/Annotation/AnnotatedField.purs
+3
-7
Core.purs
src/Gargantext/Components/NgramsTable/Core.purs
+20
-11
Config.purs
src/Gargantext/Config.purs
+1
-0
No files found.
src/Gargantext/Components/Annotation/AnnotatedField.purs
View file @
8e724e56
...
...
@@ -28,7 +28,7 @@ import Reactix.SyntheticEvent as E
import Gargantext.Types ( TermList )
import Gargantext.Components.Annotation.Utils ( termBootstrapClass )
import Gargantext.Components.NgramsTable.Core ( NgramsTerm, NgramsTable(..), _NgramsElement, _list, highlightNgrams,
nGramsRegex
)
import Gargantext.Components.NgramsTable.Core ( NgramsTerm, NgramsTable(..), _NgramsElement, _list, highlightNgrams,
findNgramTermList
)
import Gargantext.Components.Annotation.Menu ( AnnotationMenu, annotationMenu, MenuType(..) )
import Gargantext.Utils.Selection as Sel
...
...
@@ -80,10 +80,9 @@ maybeShowMenu setMenu setTermList ngrams event = do
sel' -> do
let x = E.clientX event
y = E.clientY event
sel'' = S.trim $ R.replace nGramsRegex " " sel'
list = findNgram ngrams sel''
list = findNgramTermList ngrams sel'
setList t = do
setTermList sel'
'
list t
setTermList sel' list t
setMenu (const Nothing)
E.preventDefault event
setMenu (const $ Just { x, y, list, menuType: NewNgram, setList })
...
...
@@ -100,9 +99,6 @@ maybeAddMenu _ e _ = e
compile :: NgramsTable -> Maybe String -> Array (Tuple String (Maybe TermList))
compile ngrams = maybe [] (highlightNgrams ngrams)
findNgram :: NgramsTable -> String -> Maybe TermList
findNgram (NgramsTable m) s = m ^? at s <<< _Just <<< _NgramsElement <<< _list
-- Runs
type Run =
...
...
src/Gargantext/Components/NgramsTable/Core.purs
View file @
8e724e56
module Gargantext.Components.NgramsTable.Core
( PageParams
, CoreParams
, PatchMap
, NgramsElement(..)
, _NgramsElement
, NgramsPatch(..)
...
...
@@ -11,12 +10,13 @@ module Gargantext.Components.NgramsTable.Core
, NgramsPatches
, _NgramsTable
, NgramsTerm
, normNgram
, findNgramTermList
, Version
, Versioned(..)
, VersionedNgramsTable
, CoreState
, LoadedNgramsTableProps
, nGramsRegex
, highlightNgrams
, initialPageParams
, loadNgramsTable
...
...
@@ -211,11 +211,14 @@ instance decodeJsonNgramsTable :: DecodeJson NgramsTable where
f e@(NgramsElement e') = Tuple e'.ngrams e
-----------------------------------------------------------------------------------
nGramWordBoundaries = "[ .,;:!?'\\{}()]"
nGramsRegex = case R.regex ("(" <> nGramWordBoundaries <> ")") (R.global <> R.multiline) of
wordBoundaryChars :: String
wordBoundaryChars = "[ .,;:!?'\\{}()]"
wordBoundaryReg = case R.regex ("(" <> wordBoundaryChars <> ")") (R.global <> R.multiline) of
Left e -> unsafePartial $ crashWith e
Right r -> r
nGramsRegex2 = case R.regex ("(" <> nGramWordBoundaries <> ")\\1") (R.global <> R.multiline) of
wordBoundaryReg2 = case R.regex ("(" <> wordBoundaryChars <> ")\\1") (R.global <> R.multiline) of
Left e -> unsafePartial $ crashWith e
Right r -> r
...
...
@@ -227,15 +230,15 @@ highlightNgrams (NgramsTable table) input0 =
let sN = unsafePartial (foldl goFold {i0: 0, s: input, l: Nil} ixs) in
A.reverse (A.fromFoldable (consNonEmpty (undb (init sN.s)) sN.l))
where
spR x = " " <> R.replace
nGramsRegex
"$1$1" x <> " "
reR = R.replace
nGramsRegex
" "
spR x = " " <> R.replace
wordBoundaryReg
"$1$1" x <> " "
reR = R.replace
wordBoundaryReg
" "
db = S.replace (S.Pattern " ") (S.Replacement " ")
sp x = " " <> db x <> " "
undb = R.replace
nGramsRegex
2 "$1"
undb = R.replace
wordBoundaryReg
2 "$1"
init x = S.take (S.length x - 1) x
input = spR input0
pats = A.fromFoldable (Map.keys table)
ixs
= indicesOfAny (sp <$> pats) (S.toLower $ reR
input)
ixs
= indicesOfAny (sp <$> pats) (normNgram
input)
consOnJustTail s xs@(Tuple _ (Just _) : _) =
Tuple s Nothing : xs
...
...
@@ -483,8 +486,14 @@ type NgramsTablePatch =
fromNgramsPatches :: NgramsPatches -> NgramsTablePatch
fromNgramsPatches ngramsPatches = {ngramsNewElems: mempty, ngramsPatches}
normNgram :: String -> NgramsTerm
normNgram = S.toLower <<< R.replace wordBoundaryReg " "
findNgramTermList :: NgramsTable -> String -> Maybe TermList
findNgramTermList (NgramsTable m) s = m ^? at (normNgram s) <<< _Just <<< _NgramsElement <<< _list
singletonNgramsTablePatch :: NgramsTerm -> NgramsPatch -> NgramsTablePatch
singletonNgramsTablePatch n p = fromNgramsPatches $ singletonPatchMap (
S.toLower
n) p
singletonNgramsTablePatch n p = fromNgramsPatches $ singletonPatchMap (
normNgram
n) p
type RootParent = { root :: NgramsTerm, parent :: NgramsTerm }
...
...
@@ -559,7 +568,7 @@ postNewElems newElems params = void $ traverseWithIndex postNewElem newElems
addNewNgram :: NgramsTerm -> TermList -> NgramsTablePatch
addNewNgram ngrams list = { ngramsPatches: mempty
, ngramsNewElems: Map.singleton (
S.toLower
ngrams) list }
, ngramsNewElems: Map.singleton (
normNgram
ngrams) list }
putNgramsPatches :: {nodeId :: Int, listIds :: Array Int, tabType :: TabType} -> Versioned NgramsPatches -> Aff (Versioned NgramsPatches)
putNgramsPatches {nodeId, listIds, tabType} =
...
...
src/Gargantext/Config.purs
View file @
8e724e56
...
...
@@ -207,6 +207,7 @@ pathUrl c (Chart {chartType, tabType}) i =
------------------------------------------------------------
routesPath :: R.Routes -> String
routesPath R.Home = ""
routesPath R.Login = "login"
routesPath R.SearchView = "search"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment