Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
159
Issues
159
List
Board
Labels
Milestones
Merge Requests
6
Merge Requests
6
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
haskell-gargantext
Commits
d8bdcdee
Commit
d8bdcdee
authored
May 26, 2025
by
Alfredo Di Napoli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tighten API exports of Gargantext.Core.Text.Terms.WithList
parent
97b483d7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
11 deletions
+23
-11
WithList.hs
src/Gargantext/Core/Text/Terms/WithList.hs
+23
-11
No files found.
src/Gargantext/Core/Text/Terms/WithList.hs
View file @
d8bdcdee
...
...
@@ -14,7 +14,16 @@ commentary with @some markup@.
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ViewPatterns #-}
module
Gargantext.Core.Text.Terms.WithList
where
module
Gargantext.Core.Text.Terms.WithList
(
termsInText
,
buildPatterns
,
Patterns
,
Pattern
(
..
)
,
MatchedText
,
buildPatternsWith
,
extractTermsWithList
,
extractTermsWithList'
)
where
import
Data.Algorithms.KMP
qualified
as
KMP
import
Data.IntMap.Strict
qualified
as
IntMap
...
...
@@ -68,19 +77,22 @@ replaceTerms rplaceTerms pats terms = go 0
if
len2
<
len1
then
(
len1
,
lab1
)
else
(
len2
,
lab2
)
buildPatternsWith
::
Lang
->
[
NgramsTerm
]
->
Patterns
buildPatternsWith
ZH
ts
=
buildPatterns
$
map
(
\
k
->
(
Text
.
chunksOf
1
$
unNgramsTerm
k
,
[]
))
ts
buildPatternsWith
_
ts
=
buildPatterns
$
map
(
\
k
->
(
Text
.
splitOn
" "
$
unNgramsTerm
k
,
[]
))
ts
buildPatternsWith
ZH
ts
=
buildPatterns
$
map
(
\
(
NgramsTerm
k
)
->
(
Text
.
chunksOf
1
k
,
[]
))
ts
buildPatternsWith
_
ts
=
buildPatterns
$
map
(
\
(
NgramsTerm
k
)
->
(
Text
.
splitOn
" "
k
,
[]
))
ts
buildPatterns
::
TermList
->
Patterns
buildPatterns
=
sortWith
(
Down
.
_pat_length
)
.
concatMap
buildPattern
buildPatterns
=
sortWith
(
Down
.
_pat_length
)
.
concatMap
(
uncurry
buildPattern
)
where
buildPattern
(
label
,
alts
)
=
map
f
$
map
(
\
alt
->
filter
(
/=
""
)
alt
)
(
label
:
alts
)
where
f
alt
|
""
`
elem
`
alt
=
errorTrace
(
"buildPatterns: ERR1"
<>
show
(
label
))
|
null
alt
=
errorTrace
"buildPatterns: ERR2"
|
otherwise
=
Pattern
(
KMP
.
build
alt
)
(
length
alt
)
label
--(Terms label $ Set.empty) -- TODO check stems
buildPattern
::
Label
->
[
MultiTerm
]
->
[
Pattern
]
buildPattern
label
alts
=
mapMaybe
(
mkPattern
label
)
$
map
(
\
alt
->
filter
(
/=
""
)
alt
)
(
label
:
alts
)
mkPattern
::
Label
->
[
Text
]
->
Maybe
Pattern
mkPattern
label
alt
|
""
`
elem
`
alt
=
Nothing
|
null
alt
=
Nothing
|
otherwise
=
Just
$
Pattern
(
KMP
.
build
alt
)
(
length
alt
)
label
--(Terms label $ Set.empty) -- TODO check stems
--------------------------------------------------------------------------
...
...
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