Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
GarganTexternal tools
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Julien Moutinho
GarganTexternal tools
Commits
485bc840
Commit
485bc840
authored
Jul 21, 2023
by
Loïc Chapron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mergeTermListJson
parent
e5f6aa75
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
112 additions
and
0 deletions
+112
-0
README.md
Merge/MergeTermListJson/README.md
+20
-0
mergeTwoJsonLists.py
Merge/MergeTermListJson/mergeTwoJsonLists.py
+90
-0
TermChat.json
Merge/MergeTermListJson/sample/TermChat.json
+1
-0
TermChien.json
Merge/MergeTermListJson/sample/TermChien.json
+1
-0
No files found.
Merge/MergeTermListJson/README.md
0 → 100644
View file @
485bc840
# MergeTwoJsonLists
## About The project
MergeTwoJsonLists get two Json term list from Gargantext and merge them.
## Usage
```
shell
python3 mergeTwoJsonLists.py list1.json list2.json
```
list1.json / list2.json -> GarganText Term list
Output a new list of term : list1-merged.json
## Date
This script have been last updated the 2023/07/21.
It can be outdated if the futur.
\ No newline at end of file
Merge/MergeTermListJson/mergeTwoJsonLists.py
0 → 100644
View file @
485bc840
#######
# mergeListV4.py
# description : merge two list v4
# licence : AGPL + CECILL v3
# author : quentin lobbé - qlobbe@iscpif.fr
#######
# python3 mergeListV4.py list1.json list2.json
import
sys
import
json
try
:
pathList1
=
sys
.
argv
[
1
]
pathList2
=
sys
.
argv
[
2
]
except
:
print
(
"! args error
\n
Try : python3 mergeListV4.py list1.json list2.json
\n
"
)
sys
.
exit
(
0
)
def
readJson
(
path
)
:
file
=
open
(
path
)
return
json
.
load
(
file
)
listJson1
=
readJson
(
pathList1
)
listJson2
=
readJson
(
pathList2
)
ngrams1
=
listJson1
[
'NgramsTerms'
][
'data'
]
ngrams2
=
listJson2
[
'NgramsTerms'
][
'data'
]
merged
=
{}
roots
=
[]
leafs
=
[]
# find the roots of list 1
for
root
in
ngrams1
.
keys
()
:
if
ngrams1
[
root
][
'list'
]
==
"MapTerm"
:
roots
.
append
(
root
)
leafs
=
leafs
+
ngrams1
[
root
][
'children'
]
# merge list 2 in list 1
for
root
in
ngrams2
.
keys
()
:
if
root
in
roots
:
ngrams1
[
root
][
'children'
]
=
list
(
set
(
ngrams1
[
root
][
'children'
]
+
ngrams2
[
root
][
'children'
]))
else
:
if
root
not
in
leafs
:
ngrams1
[
root
]
=
ngrams2
[
root
]
children
=
ngrams1
[
root
][
'children'
]
ngrams1
[
root
][
'children'
]
=
[]
for
child
in
children
:
if
child
not
in
root
or
child
not
in
leafs
:
ngrams1
[
root
][
'children'
]
.
append
(
child
)
# clean the merged list
for
root
in
ngrams1
.
keys
()
:
if
ngrams1
[
root
][
'list'
]
==
"MapTerm"
:
if
len
(
ngrams1
[
root
][
'children'
])
==
0
:
ngrams1
[
root
][
'children'
]
=
[]
merged
[
root
]
=
ngrams1
[
root
]
listJson1
[
'NgramsTerms'
][
'data'
]
=
merged
listJson1
[
'Authors'
][
'data'
]
=
{}
listJson1
[
'Institutes'
][
'data'
]
=
{}
listJson1
[
'Sources'
][
'data'
]
=
{}
name
=
((
pathList1
.
split
(
'/'
))
.
pop
())
.
split
(
'.'
)
newName
=
name
[
0
]
+
'-merged.'
+
name
[
1
]
if
len
(
pathList1
.
split
(
'/'
))
==
1
:
newPath
=
newName
else
:
newPath
=
'/'
.
join
((
pathList1
.
split
(
'/'
))[:
-
1
])
+
'/'
+
newName
with
open
(
newPath
,
'w'
)
as
file
:
json
.
dump
(
listJson1
,
file
,
sort_keys
=
False
,
indent
=
4
)
Merge/MergeTermListJson/sample/TermChat.json
0 → 100644
View file @
485bc840
This diff is collapsed.
Click to expand it.
Merge/MergeTermListJson/sample/TermChien.json
0 → 100644
View file @
485bc840
This diff is collapsed.
Click to expand it.
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