Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gargantext
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
ca339c4a
Commit
ca339c4a
authored
May 31, 2016
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
annotations: finished grouped forms integration (they are now highlighted like mainforms)
parent
fb3ef8fa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
14 deletions
+56
-14
views.py
annotations/views.py
+56
-14
No files found.
annotations/views.py
View file @
ca339c4a
...
@@ -12,15 +12,11 @@ from rest_framework.renderers import JSONRenderer
...
@@ -12,15 +12,11 @@ from rest_framework.renderers import JSONRenderer
from
rest_framework.exceptions
import
APIException
from
rest_framework.exceptions
import
APIException
from
rest_framework.authentication
import
SessionAuthentication
,
BasicAuthentication
from
rest_framework.authentication
import
SessionAuthentication
,
BasicAuthentication
# 2016-03-24: refactoring, new paths
from
gargantext.models.ngrams
import
Node
,
NodeNgram
,
Ngram
,
NodeNgramNgram
from
gargantext.models.ngrams
import
Node
,
NodeNgram
,
Ngram
from
gargantext.util.db
import
session
,
aliased
from
gargantext.util.db
import
session
,
aliased
from
gargantext.util.db_cache
import
cache
from
gargantext.util.db_cache
import
cache
from
gargantext.util.http
import
requires_auth
from
gargantext.util.http
import
requires_auth
from
sqlalchemy.sql.expression
import
case
# from ngram.lists import listIds, listNgramIds
# from gargantext_web.db import get_or_create_node
@
requires_auth
@
requires_auth
def
main
(
request
,
project_id
,
corpus_id
,
document_id
):
def
main
(
request
,
project_id
,
corpus_id
,
document_id
):
...
@@ -39,7 +35,16 @@ class NgramList(APIView):
...
@@ -39,7 +35,16 @@ class NgramList(APIView):
renderer_classes
=
(
JSONRenderer
,)
renderer_classes
=
(
JSONRenderer
,)
def
get
(
self
,
request
,
corpus_id
,
doc_id
):
def
get
(
self
,
request
,
corpus_id
,
doc_id
):
"""Get All for a doc id"""
"""
Get all ngrams for a doc id, sorted by list
NB1 : we are within a doc only
NB2 : MAINLIST items are actually MAINLIST without MAP items
NB3 : mostly the mainforms are in lists, but doc can have subform
=> if we simply join on ngram_id, we'll filter out the subforms
=> join on value filled by case switch:
(the ngram itself or a mainform if exists)
"""
corpus_id
=
int
(
corpus_id
)
corpus_id
=
int
(
corpus_id
)
doc_id
=
int
(
doc_id
)
doc_id
=
int
(
doc_id
)
...
@@ -51,8 +56,16 @@ class NgramList(APIView):
...
@@ -51,8 +56,16 @@ class NgramList(APIView):
corpus_nod
=
cache
.
Node
[
corpus_id
]
corpus_nod
=
cache
.
Node
[
corpus_id
]
doc_nod
=
cache
.
Node
[
doc_id
]
doc_nod
=
cache
.
Node
[
doc_id
]
scores_nod
=
corpus_nod
.
children
(
typename
=
"OCCURRENCES"
)
.
first
()
scores_nod
=
corpus_nod
.
children
(
typename
=
"OCCURRENCES"
)
.
first
()
groups_nod
=
corpus_nod
.
children
(
typename
=
"GROUPLIST"
)
.
first
()
# synonyms sub table for outerjoins
Syno
=
(
session
.
query
(
NodeNgramNgram
.
ngram1_id
,
NodeNgramNgram
.
ngram2_id
)
.
filter
(
NodeNgramNgram
.
node_id
==
groups_nod
.
id
)
.
subquery
()
)
# maplist_ids to filter
them
from mainlist
# maplist_ids to filter
map ngrams
from mainlist
maplist_ids
=
{}
maplist_ids
=
{}
# NB must do mainlist after map for filtering map items out of main
# NB must do mainlist after map for filtering map items out of main
...
@@ -63,23 +76,52 @@ class NgramList(APIView):
...
@@ -63,23 +76,52 @@ class NgramList(APIView):
ListsTable
=
aliased
(
NodeNgram
)
ListsTable
=
aliased
(
NodeNgram
)
# doc_nod.ngrams iff we just need the occurrences in the doc (otherwise do manually)
mainform_id
=
case
([
q
=
doc_nod
.
ngrams
.
join
(
ListsTable
)
.
filter
(
ListsTable
.
node_id
==
list_id
)
(
Syno
.
c
.
ngram1_id
!=
None
,
Syno
.
c
.
ngram1_id
),
(
Syno
.
c
.
ngram1_id
==
None
,
Ngram
.
id
)
])
q
=
(
session
# ngrams from the doc_id
.
query
(
NodeNgram
.
weight
,
Ngram
,
mainform_id
)
# debug
#.query(NodeNgram.weight, Ngram.terms, Ngram.id, Syno.c.ngram1_id, mainform_id)
.
select_from
(
NodeNgram
)
.
join
(
Ngram
)
.
filter
(
NodeNgram
.
node_id
==
doc_id
)
# add mainforms next to their subforms
.
outerjoin
(
Syno
,
Syno
.
c
.
ngram2_id
==
Ngram
.
id
)
# filter mainforms on the list we want
.
join
(
ListsTable
,
# possible that mainform is in list
# and not the subform
ListsTable
.
ngram_id
==
mainform_id
)
.
filter
(
ListsTable
.
node_id
==
list_id
)
)
# add to results (and optional filtering)
# add to results (and optional filtering)
for
(
w
,
obj
)
in
q
.
all
():
for
(
w
,
obj
,
mainform_id
)
in
q
.
all
():
ngram_id
=
obj
.
id
# boolean if needed
# is_subform = (ngram_id == mainform_id)
# special filtering case
# special filtering case
# when MAINLIST requested we actually want MAIN without MAP
# when MAINLIST requested we actually want MAIN without MAP
if
list_type
==
"MAPLIST"
:
if
list_type
==
"MAPLIST"
:
maplist_ids
[
obj
.
id
]
=
True
maplist_ids
[
ngram_
id
]
=
True
if
list_type
==
"MAINLIST"
:
if
list_type
==
"MAINLIST"
:
if
obj
.
id
in
maplist_ids
:
if
ngram_
id
in
maplist_ids
:
# skip object
# skip object
continue
continue
# normal case
# normal case
doc_ngram_list_add
((
obj
.
id
,
obj
.
terms
,
w
,
list_id
))
doc_ngram_list_add
((
ngram_
id
,
obj
.
terms
,
w
,
list_id
))
# debug
# debug
# print("annotations.views.NgramList.doc_ngram_list: ", doc_ngram_list)
# print("annotations.views.NgramList.doc_ngram_list: ", doc_ngram_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