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
7e426b8a
Commit
7e426b8a
authored
Jun 01, 2016
by
delanoe
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'romain-goodies' into unstable
parents
5b50e991
ca339c4a
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
105 additions
and
43 deletions
+105
-43
app.css
annotations/static/annotations/app.css
+4
-0
highlight.js
annotations/static/annotations/highlight.js
+3
-7
http.js
annotations/static/annotations/http.js
+3
-3
keyword_tpl.html
annotations/static/annotations/keyword_tpl.html
+1
-1
ngramlist.js
annotations/static/annotations/ngramlist.js
+1
-1
main.html
annotations/templates/annotations/main.html
+20
-17
views.py
annotations/views.py
+73
-14
No files found.
annotations/static/annotations/app.css
View file @
7e426b8a
...
@@ -163,6 +163,10 @@
...
@@ -163,6 +163,10 @@
float
:
right
;
float
:
right
;
}
}
.spacer
{
margin-top
:
40px
;
}
.favactive
{
.favactive
{
/* yellow */
/* yellow */
color
:
#FFF50D
;
color
:
#FFF50D
;
...
...
annotations/static/annotations/highlight.js
View file @
7e426b8a
...
@@ -118,12 +118,8 @@
...
@@ -118,12 +118,8 @@
// * (see also InferCRUDFlags in lib/NGrams_dyna_chart_and_table)
// * (see also InferCRUDFlags in lib/NGrams_dyna_chart_and_table)
// ---------------------------------------------------------------
// ---------------------------------------------------------------
// TODO disambiguate annotation.list_id for highlighted MapList items
// NB: remember that shown mainlist items are actually main 'without map'
// -------------------------------------------------------------
// otherwise the menu for mainlist items can hide the menu for map items
// Because MapList annotations are also MiamList,
// we should ensure that list_id is indeed "MapList"
// (ie that it was added last in CompileNgramsHtml)
// otherwise the "if" here will propose MiamList's options
if
(
$rootScope
.
lists
[
annotation
.
list_id
]
==
"MAPLIST"
)
{
if
(
$rootScope
.
lists
[
annotation
.
list_id
]
==
"MAPLIST"
)
{
$scope
.
menuItems
.
push
({
$scope
.
menuItems
.
push
({
...
@@ -385,7 +381,7 @@
...
@@ -385,7 +381,7 @@
// =============
// =============
// text ------- "Background Few previous studies have examined
// text ------- "Background Few previous studies have examined
// non-wealth-based inequalities etc etc etc"
// non-wealth-based inequalities etc etc etc"
// ngram ----- {uuid: 1846, occ
urrence
s: 1, list_id: 3689,
// ngram ----- {uuid: 1846, occs: 1, list_id: 3689,
// text: "previous studies", listName: "MAINLIST"}
// text: "previous studies", listName: "MAINLIST"}
// template --- "<span ng-controller='TextSelectionController'
// template --- "<span ng-controller='TextSelectionController'
// ng-click='onClick($event)'
// ng-click='onClick($event)'
...
...
annotations/static/annotations/http.js
View file @
7e426b8a
...
@@ -64,9 +64,9 @@
...
@@ -64,9 +64,9 @@
* --------
* --------
* "554": {
* "554": {
* "lists": { "558": "StopList", "564": "MiamList", "565": "MapList" }
* "lists": { "558": "StopList", "564": "MiamList", "565": "MapList" }
* "556": [{ "uuid": 2368, "occ
urrence
s": 1.0, "text": "idea", "list_id": 564 },
* "556": [{ "uuid": 2368, "occs": 1.0, "text": "idea", "list_id": 564 },
* { "uuid": 5031, "occ
urrence
s": 1.0, "text": "indications", "list_id": 564},
* { "uuid": 5031, "occs": 1.0, "text": "indications", "list_id": 564},
* { "uuid": 5015, "occ
urrence
s": 3.0, "text": "star", "list_id": 565 },
* { "uuid": 5015, "occs": 3.0, "text": "star", "list_id": 565 },
* ... ],
* ... ],
* }
* }
*/
*/
...
...
annotations/static/annotations/keyword_tpl.html
View file @
7e426b8a
<span
ng-click=
'onDeleteClick()'
class=
"delete-keyword"
>
×
</span>
<span
ng-click=
'onDeleteClick()'
class=
"delete-keyword"
>
×
</span>
<span
data-toggle=
"tooltip"
class=
"keyword-text {[{keyword.listName}]}"
>
{[{keyword.text}]}
</span>
<span
data-toggle=
"tooltip"
class=
"keyword-text {[{keyword.listName}]}"
>
{[{keyword.text}]}
</span>
<span
class=
"occurrences"
data-keyword-id=
"{[{keyword.uuid}]}"
>
{[{keyword.occ
urrence
s}]}
</span>
<span
class=
"occurrences"
data-keyword-id=
"{[{keyword.uuid}]}"
>
{[{keyword.occs}]}
</span>
annotations/static/annotations/ngramlist.js
View file @
7e426b8a
...
@@ -159,7 +159,7 @@
...
@@ -159,7 +159,7 @@
// £TEST locally check if already in annotations NodeNgrams ------
// £TEST locally check if already in annotations NodeNgrams ------
// $rootScope.annotations = array of ngram objects like:
// $rootScope.annotations = array of ngram objects like:
// {"list_id":805,"occ
urrence
s":2,"uuid":9386,"text":"petit échantillon"}
// {"list_id":805,"occs":2,"uuid":9386,"text":"petit échantillon"}
console
.
log
(
'looking for "'
+
value
+
'" in list:'
+
listId
)
console
.
log
(
'looking for "'
+
value
+
'" in list:'
+
listId
)
var
already_in_list
=
false
;
var
already_in_list
=
false
;
...
...
annotations/templates/annotations/main.html
View file @
7e426b8a
...
@@ -25,12 +25,24 @@
...
@@ -25,12 +25,24 @@
<div
class=
"container-fluid"
>
<div
class=
"container-fluid"
>
<div
class=
"row-fluid main-panel"
ng-controller=
"NGramHighlightController"
>
<div
class=
"row-fluid main-panel"
ng-controller=
"NGramHighlightController"
>
<div
class=
"col-md-4 col-xs-4 tabbable words-panel"
>
<div
class=
"col-md-4 col-xs-4 tabbable words-panel"
>
<ul
class=
"nav nav-pills nav-justified"
>
<div
class=
"list-selector"
>
<li
ng-repeat=
"(listId, listName) in activeLists"
ng-class=
"{active: $first == true}"
>
<h5>
Select highlighted list(s)
<a
href=
"#tab-{[{listId}]}"
data-toggle=
"tab"
>
{[{listName}]}
</a>
<select
class=
"selectpicker"
multiple
ng-change=
"activeListsChange()"
ng-model=
"lists"
ng-controller=
"ActiveListsController"
>
</li>
</ul>
<option
ng-repeat=
"item in allListsSelect"
id=
"list---{[{item.id}]}"
ng-disabled=
"{[{ item.label == 'MAPLIST' }]}"
>
{[{item.label}]}
</option>
<div
class=
"tab-content"
>
<!-- to disallow unchecking MapList add this into <option> element: ng-disabled="{[{ item.label == 'MAPLIST' }]}" -->
</select>
</h5>
<div
class=
"row spacer"
></div>
<ul
class=
"nav nav-pills nav-justified"
>
<li
ng-repeat=
"(listId, listName) in activeLists"
ng-class=
"{active: $first == true}"
>
<a
href=
"#tab-{[{listId}]}"
data-toggle=
"tab"
>
{[{listName}]}
</a>
</li>
</ul>
</div>
<div
class=
"tab-content"
>
<div
ng-controller=
"NgramListPaginationController"
ng-repeat=
"(listId, listName) in activeLists"
ng-class=
"{active: $first == true}"
class=
"tab-pane"
id=
"tab-{[{listId}]}"
>
<div
ng-controller=
"NgramListPaginationController"
ng-repeat=
"(listId, listName) in activeLists"
ng-class=
"{active: $first == true}"
class=
"tab-pane"
id=
"tab-{[{listId}]}"
>
<div
ng-if=
"ngramsInPanel[listId].length == 0"
class=
"alert alert-info"
role=
"alert"
>
<div
ng-if=
"ngramsInPanel[listId].length == 0"
class=
"alert alert-info"
role=
"alert"
>
Input any keyword you want to link to this article and the list named '{[{listName}]}'
Input any keyword you want to link to this article and the list named '{[{listName}]}'
...
@@ -48,23 +60,14 @@
...
@@ -48,23 +60,14 @@
<li
ng-class=
"{'disabled': currentListPage >= totalListPages(listId) - 1}"
><a
ng-click=
"nextListPage()"
class=
"glyphicon glyphicon-forward"
></a></li>
<li
ng-class=
"{'disabled': currentListPage >= totalListPages(listId) - 1}"
><a
ng-click=
"nextListPage()"
class=
"glyphicon glyphicon-forward"
></a></li>
</ul>
</ul>
</nav>
</nav>
<!--
<div class="form-group" ng-controller="NgramInputController">
<div class="form-group" ng-controller="NgramInputController">
<input autosave="search" maxlength="240" placeholder="Add any text" type="text" class="form-control" id="{[{listId}]}-input" ng-keypress="onListSubmit($event, listId)">
<input autosave="search" maxlength="240" placeholder="Add any text" type="text" class="form-control" id="{[{listId}]}-input" ng-keypress="onListSubmit($event, listId)">
<button type="submit" class="form-control btn btn-default btn-primary" ng-click="onListSubmit($event, listId)">Add to {[{listName}]}</button>
<button type="submit" class="form-control btn btn-default btn-primary" ng-click="onListSubmit($event, listId)">Add to {[{listName}]}</button>
</div>
</div>
-->
</div>
</div>
</div>
</div>
<div
class=
"list-selector"
>
<h5>
Select lists
</h5>
<select
class=
"selectpicker"
multiple
ng-change=
"activeListsChange()"
ng-model=
"lists"
ng-controller=
"ActiveListsController"
>
<option
ng-repeat=
"item in allListsSelect"
id=
"list---{[{item.id}]}"
>
{[{item.label}]}
</option>
<!-- to disallow unchecking MapList add this into <option> element: ng-disabled="{[{ item.label == 'MapList' }]}" -->
</select>
</div>
</div>
</div>
<div
class=
"col-md-8 col-xs-8 text-panel"
ng-controller=
"DocController"
id=
"document"
>
<div
class=
"col-md-8 col-xs-8 text-panel"
ng-controller=
"DocController"
id=
"document"
>
<div
class=
"row-fluid clearfix"
>
<div
class=
"row-fluid clearfix"
>
...
...
annotations/views.py
View file @
7e426b8a
...
@@ -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,30 +35,93 @@ class NgramList(APIView):
...
@@ -39,30 +35,93 @@ 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
)
# our results: ngrams for the corpus_id (ignoring doc_id for the moment)
# our results: ngrams for the corpus_id (ignoring doc_id for the moment)
doc_ngram_list
=
[]
doc_ngram_list
=
[]
doc_ngram_list_add
=
doc_ngram_list
.
append
lists
=
{}
lists
=
{}
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
()
)
for
list_type
in
[
'MAINLIST'
,
'MAPLIST'
,
'STOPLIST'
]:
# maplist_ids to filter map ngrams from mainlist
maplist_ids
=
{}
# NB must do mainlist after map for filtering map items out of main
for
list_type
in
[
'MAPLIST'
,
'STOPLIST'
,
'MAINLIST'
]:
list_nod
=
corpus_nod
.
children
(
typename
=
list_type
)
.
first
()
list_nod
=
corpus_nod
.
children
(
typename
=
list_type
)
.
first
()
list_id
=
list_nod
.
id
list_id
=
list_nod
.
id
lists
[
"
%
s"
%
list_id
]
=
list_type
lists
[
"
%
s"
%
list_id
]
=
list_type
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
)
# add to results
])
doc_ngram_list
+=
[(
obj
.
id
,
obj
.
terms
,
w
,
list_id
)
for
(
w
,
obj
)
in
q
.
all
()]
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)
for
(
w
,
obj
,
mainform_id
)
in
q
.
all
():
ngram_id
=
obj
.
id
# boolean if needed
# is_subform = (ngram_id == mainform_id)
# special filtering case
# when MAINLIST requested we actually want MAIN without MAP
if
list_type
==
"MAPLIST"
:
maplist_ids
[
ngram_id
]
=
True
if
list_type
==
"MAINLIST"
:
if
ngram_id
in
maplist_ids
:
# skip object
continue
# normal case
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)
...
@@ -71,7 +130,7 @@ class NgramList(APIView):
...
@@ -71,7 +130,7 @@ class NgramList(APIView):
[
[
{
'uuid'
:
ngram_id
,
{
'uuid'
:
ngram_id
,
'text'
:
ngram_text
,
'text'
:
ngram_text
,
'occ
urrence
s'
:
ngram_occurrences
,
'occs'
:
ngram_occurrences
,
'list_id'
:
list_id
,}
'list_id'
:
list_id
,}
for
(
ngram_id
,
ngram_text
,
ngram_occurrences
,
list_id
)
in
doc_ngram_list
for
(
ngram_id
,
ngram_text
,
ngram_occurrences
,
list_id
)
in
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