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
137
Issues
137
List
Board
Labels
Milestones
Merge Requests
5
Merge Requests
5
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
a1538c90
Verified
Commit
a1538c90
authored
May 30, 2023
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[annotation] [WIP] some caching
parent
baaea6e3
Pipeline
#4092
failed with stage
in 0 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
15 deletions
+36
-15
Field.purs
src/Gargantext/Components/Annotation/Field.purs
+19
-3
Functions.purs
src/Gargantext/Core/NgramsTable/Functions.purs
+17
-12
No files found.
src/Gargantext/Components/Annotation/Field.purs
View file @
a1538c90
...
@@ -14,8 +14,11 @@ module Gargantext.Components.Annotation.Field where
...
@@ -14,8 +14,11 @@ module Gargantext.Components.Annotation.Field where
import Gargantext.Prelude
import Gargantext.Prelude
import Data.Array as A
import Data.Array as A
import Data.FoldableWithIndex (foldlWithIndex, foldrWithIndex)
import Data.List (List(..), (:))
import Data.List (List(..), (:))
import Data.Map (Map)
import Data.Maybe (Maybe(..), maybe)
import Data.Maybe (Maybe(..), maybe)
import Data.Set as Set
import Data.String.Common (joinWith)
import Data.String.Common (joinWith)
import Data.Tuple (Tuple(..), snd)
import Data.Tuple (Tuple(..), snd)
import Data.Tuple.Nested ((/\))
import Data.Tuple.Nested ((/\))
...
@@ -24,7 +27,7 @@ import Effect (Effect)
...
@@ -24,7 +27,7 @@ import Effect (Effect)
import Gargantext.Components.Annotation.Menu (annotationMenu, AnnotationMenu)
import Gargantext.Components.Annotation.Menu (annotationMenu, AnnotationMenu)
import Gargantext.Components.Annotation.Types (MenuType(..), ModeType(..), termClass)
import Gargantext.Components.Annotation.Types (MenuType(..), ModeType(..), termClass)
import Gargantext.Core.NgramsTable.Functions (findNgramTermList, highlightNgrams, normNgram)
import Gargantext.Core.NgramsTable.Functions (findNgramTermList, highlightNgrams, normNgram)
import Gargantext.Core.NgramsTable.Types (HighlightElement, Ngrams
Table, NgramsTerm(..)
)
import Gargantext.Core.NgramsTable.Types (HighlightElement, Ngrams
RepoElement(..), NgramsTable(..), NgramsTerm(..), parentMap
)
import Gargantext.Types (CTabNgramType(..), TermList)
import Gargantext.Types (CTabNgramType(..), TermList)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Selection as Sel
import Gargantext.Utils.Selection as Sel
...
@@ -110,7 +113,7 @@ annotatedFieldInnerCpt = here.component "annotatedFieldInner" cpt where
...
@@ -110,7 +113,7 @@ annotatedFieldInnerCpt = here.component "annotatedFieldInner" cpt where
H.div
H.div
{ className: "annotated-field-runs" }
{ className: "annotated-field-runs" }
((\p -> annotateRun p) <$> wrap <$> compile ngrams fieldText)
((\p -> annotateRun p) <$> wrap <$> compile
Cached
ngrams fieldText)
AdditionMode ->
AdditionMode ->
...
@@ -131,11 +134,24 @@ annotatedFieldInnerCpt = here.component "annotatedFieldInner" cpt where
...
@@ -131,11 +134,24 @@ annotatedFieldInnerCpt = here.component "annotatedFieldInner" cpt where
-----------------------------------------------------------
-----------------------------------------------------------
compileCached :: NgramsTable
-> Maybe String
-> Array HighlightElement
compileCached ngrams = compile ngrams { pm, pats }
where
NgramsTable { ngrams_repo_elements } = ngrams
pm = parentMap ngrams_repo_elements
pats :: Array NgramsTerm
pats = A.fromFoldable $
foldrWithIndex (\term (NgramsRepoElement nre) acc -> Set.union acc $ Set.insert term nre.children) Set.empty ngrams_repo_elements
compile ::
compile ::
NgramsTable
NgramsTable
-> { pm :: Map NgramsTerm NgramsTerm, pats :: Array NgramsTerm }
-> Maybe String
-> Maybe String
-> Array HighlightElement
-> Array HighlightElement
compile ngrams
= maybe [] (highlightNgrams CTabTerms ngrams
)
compile ngrams
cache = maybe [] (highlightNgrams CTabTerms ngrams cache
)
-- Runs
-- Runs
...
...
src/Gargantext/Core/NgramsTable/Functions.purs
View file @
a1538c90
...
@@ -8,7 +8,7 @@ import Data.Array (head)
...
@@ -8,7 +8,7 @@ import Data.Array (head)
import Data.Array as A
import Data.Array as A
import Data.Either (Either(..))
import Data.Either (Either(..))
import Data.Foldable (foldl)
import Data.Foldable (foldl)
import Data.FoldableWithIndex (foldlWithIndex)
import Data.FoldableWithIndex (foldlWithIndex
, foldrWithIndex
)
import Data.Lens (use, view, (^?), (^.), (?=), (%~), (%=), (.~))
import Data.Lens (use, view, (^?), (^.), (?=), (%~), (%=), (.~))
import Data.Lens.At (at)
import Data.Lens.At (at)
import Data.Lens.Common (_Just)
import Data.Lens.Common (_Just)
...
@@ -114,11 +114,11 @@ lookupRootList ngram (NgramsTable {ngrams_repo_elements: elts}) =
...
@@ -114,11 +114,11 @@ lookupRootList ngram (NgramsTable {ngrams_repo_elements: elts}) =
Nothing -> Nothing
Nothing -> Nothing
Just (NgramsRepoElement {list}) -> Just list -- assert root == Nothing
Just (NgramsRepoElement {list}) -> Just list -- assert root == Nothing
lookupRootListWithChildren :: NgramsTerm -> NgramsTable ->
Map NgramsTerm NgramsTerm
-> Maybe TermList
lookupRootListWithChildren :: NgramsTerm -> NgramsTable ->
Cache
-> Maybe TermList
lookupRootListWithChildren ngram table@(NgramsTable {ngrams_repo_elements: elts})
parentMap'
=
lookupRootListWithChildren ngram table@(NgramsTable {ngrams_repo_elements: elts})
{ pm, pats }
=
case Map.lookup ngram elts of
case Map.lookup ngram elts of
Nothing -> -- try to find in children
Nothing -> -- try to find in children
case Map.lookup ngram p
arentMap'
of
case Map.lookup ngram p
m
of
Nothing -> Nothing
Nothing -> Nothing
Just parent' -> lookupRootList parent' table
Just parent' -> lookupRootList parent' table
Just (NgramsRepoElement {list, root: Nothing}) -> Just list
Just (NgramsRepoElement {list, root: Nothing}) -> Just list
...
@@ -140,10 +140,13 @@ wordBoundaryReg2 = case R.regex ("(" <> wordBoundaryChars <> ")\\1") (R.global <
...
@@ -140,10 +140,13 @@ wordBoundaryReg2 = case R.regex ("(" <> wordBoundaryChars <> ")\\1") (R.global <
Left e -> unsafePartial $ crashWith e
Left e -> unsafePartial $ crashWith e
Right r -> r
Right r -> r
type Cache = { pm :: Map NgramsTerm NgramsTerm
, pats :: Array NgramsTerm }
-- TODO: while this function works well with word boundaries,
-- TODO: while this function works well with word boundaries,
-- it inserts too many spaces.
-- it inserts too many spaces.
highlightNgrams :: CTabNgramType -> NgramsTable -> String -> Array HighlightElement
highlightNgrams :: CTabNgramType -> NgramsTable ->
Cache ->
String -> Array HighlightElement
highlightNgrams ntype table@(NgramsTable {ngrams_repo_elements: elts}) input0 =
highlightNgrams ntype table@(NgramsTable {ngrams_repo_elements: elts})
{ pm, pats }
input0 =
-- trace {pats, input0, input, ixs} \_ ->
-- trace {pats, input0, input, ixs} \_ ->
A.fromFoldable ((\(s /\ ls)-> undb s /\ ls) <$> unsafePartial (foldl goFold ((input /\ Nil) : Nil) ixs))
A.fromFoldable ((\(s /\ ls)-> undb s /\ ls) <$> unsafePartial (foldl goFold ((input /\ Nil) : Nil) ixs))
where
where
...
@@ -154,9 +157,11 @@ highlightNgrams ntype table@(NgramsTable {ngrams_repo_elements: elts}) input0 =
...
@@ -154,9 +157,11 @@ highlightNgrams ntype table@(NgramsTable {ngrams_repo_elements: elts}) input0 =
undb = R.replace wordBoundaryReg2 "$1"
undb = R.replace wordBoundaryReg2 "$1"
input = spR input0
input = spR input0
-- pats = A.fromFoldable (Map.keys elts)
-- pats = A.fromFoldable (Map.keys elts)
pats :: Array NgramsTerm
-- pats :: Array NgramsTerm
pats = A.fromFoldable $
-- pats = A.fromFoldable $
foldlWithIndex (\term acc (NgramsRepoElement nre) -> Set.union acc $ Set.insert term nre.children) Set.empty elts
-- foldrWithIndex (\term (NgramsRepoElement nre) acc -> Set.union acc $ Set.insert term nre.childre
-- n) Set.empty elts
-- foldlWithIndex (\term acc (NgramsRepoElement nre) -> Set.union acc $ Set.insert term nre.children) Set.empty elts
hashStruct = SSKR.hashStruct (sp <<< ngramsTermText <$> pats)
hashStruct = SSKR.hashStruct (sp <<< ngramsTermText <$> pats)
ixs = SSKR.indicesOfAnyHashStruct hashStruct (normNgramInternal ntype input)
ixs = SSKR.indicesOfAnyHashStruct hashStruct (normNgramInternal ntype input)
...
@@ -185,12 +190,12 @@ highlightNgrams ntype table@(NgramsTable {ngrams_repo_elements: elts}) input0 =
...
@@ -185,12 +190,12 @@ highlightNgrams ntype table@(NgramsTable {ngrams_repo_elements: elts}) input0 =
addNgramElt ng ne_list (elt /\ elt_lists) = (elt /\ ((ng /\ ne_list) : elt_lists))
addNgramElt ng ne_list (elt /\ elt_lists) = (elt /\ ((ng /\ ne_list) : elt_lists))
parentMap' :: Map NgramsTerm NgramsTerm
--
parentMap' :: Map NgramsTerm NgramsTerm
parentMap' = parentMap elts
--
parentMap' = parentMap elts
goAcc :: Partial => Int -> HighlightAccumulator -> Tuple NgramsTerm Int -> HighlightAccumulator
goAcc :: Partial => Int -> HighlightAccumulator -> Tuple NgramsTerm Int -> HighlightAccumulator
goAcc i acc (pat /\ lpat) =
goAcc i acc (pat /\ lpat) =
case lookupRootListWithChildren pat table
parentMap'
of
case lookupRootListWithChildren pat table
{ pm, pats }
of
Nothing ->
Nothing ->
crashWith "highlightNgrams: pattern missing from table"
crashWith "highlightNgrams: pattern missing from table"
Just ne_list ->
Just ne_list ->
...
...
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