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
e8590680
Commit
e8590680
authored
Jun 12, 2015
by
Elias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adapted ngramList for annocations api
parent
782efa8c
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
89 additions
and
59 deletions
+89
-59
app.css
annotations/static/annotations/app.css
+2
-2
app.js
annotations/static/annotations/app.js
+31
-17
http.js
annotations/static/annotations/http.js
+1
-1
keyword_tpl.html
annotations/static/annotations/keyword_tpl.html
+5
-5
selection_tpl.html
annotations/static/annotations/selection_tpl.html
+7
-7
urls.py
annotations/urls.py
+1
-1
views.py
annotations/views.py
+19
-4
settings.py
gargantext_web/settings.py
+0
-1
lists.py
ngram/lists.py
+23
-21
No files found.
annotations/static/annotations/app.css
View file @
e8590680
...
@@ -27,13 +27,13 @@
...
@@ -27,13 +27,13 @@
border-bottom
:
none
;
border-bottom
:
none
;
}
}
.miam
word
{
.miam
list
{
color
:
black
;
color
:
black
;
background-color
:
rgba
(
60
,
118
,
61
,
0.5
);
background-color
:
rgba
(
60
,
118
,
61
,
0.5
);
cursor
:
pointer
;
cursor
:
pointer
;
}
}
.stop
word
{
.stop
list
{
color
:
black
;
color
:
black
;
background-color
:
rgba
(
169
,
68
,
66
,
0.2
);
background-color
:
rgba
(
169
,
68
,
66
,
0.2
);
cursor
:
pointer
;
cursor
:
pointer
;
...
...
annotations/static/annotations/app.js
View file @
e8590680
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
function
(
$scope
,
$rootScope
,
$element
,
NgramHttpService
)
{
function
(
$scope
,
$rootScope
,
$element
,
NgramHttpService
)
{
// TODO use the tooltip ?
// TODO use the tooltip ?
$scope
.
onDeleteClick
=
function
()
{
$scope
.
onDeleteClick
=
function
()
{
// TODO not the right params
NgramHttpService
.
delete
(
$scope
.
keyword
,
$rootScope
);
NgramHttpService
.
delete
(
$scope
.
keyword
,
$rootScope
);
};
};
}]);
}]);
...
@@ -91,9 +92,13 @@
...
@@ -91,9 +92,13 @@
function
toggleMenu
(
context
,
annotation
){
function
toggleMenu
(
context
,
annotation
){
$timeout
(
function
()
{
$timeout
(
function
()
{
$scope
.
$apply
(
function
()
{
$scope
.
$apply
(
function
()
{
$scope
.
miamListId
=
_
.
invert
(
$rootScope
.
lists
)[
'MiamList'
];
$scope
.
stopListId
=
_
.
invert
(
$rootScope
.
lists
)[
'StopList'
];;
if
(
angular
.
isObject
(
annotation
))
{
if
(
angular
.
isObject
(
annotation
))
{
$scope
.
level
=
angular
.
copy
(
annotation
.
level
);
$scope
.
level
=
angular
.
copy
(
annotation
.
level
);
$scope
.
category
=
angular
.
copy
(
annotation
.
category
);
$scope
.
category
=
$rootScope
.
lists
[
annotation
.
list_id
].
toLowerCase
();
$scope
.
listId
=
angular
.
copy
(
annotation
.
list_id
);
// used in onClick
// used in onClick
$scope
.
selection_text
=
angular
.
copy
(
annotation
);
$scope
.
selection_text
=
angular
.
copy
(
annotation
);
...
@@ -118,7 +123,7 @@
...
@@ -118,7 +123,7 @@
}
}
else
if
(
annotation
.
trim
()
!==
""
)
{
else
if
(
annotation
.
trim
()
!==
""
)
{
$scope
.
selection_text
=
angular
.
copy
(
annotation
);
$scope
.
selection_text
=
angular
.
copy
(
annotation
);
$scope
.
level
=
"
Create from current
selection"
;
$scope
.
level
=
"
New Ngram from
selection"
;
$scope
.
category
=
null
;
$scope
.
category
=
null
;
$scope
.
local_miamlist
=
true
;
$scope
.
local_miamlist
=
true
;
$scope
.
local_stoplist
=
true
;
$scope
.
local_stoplist
=
true
;
...
@@ -166,26 +171,34 @@
...
@@ -166,26 +171,34 @@
$rootScope
.
$on
(
"positionAnnotationMenu"
,
positionElement
);
$rootScope
.
$on
(
"positionAnnotationMenu"
,
positionElement
);
$rootScope
.
$on
(
"toggleAnnotationMenu"
,
toggleMenu
);
$rootScope
.
$on
(
"toggleAnnotationMenu"
,
toggleMenu
);
$scope
.
onClick
=
function
(
$event
,
action
,
category
,
level
)
{
$scope
.
onClick
=
function
(
$event
,
action
,
listId
)
{
if
(
angular
.
isObject
(
$scope
.
selection_text
))
{
if
(
angular
.
isObject
(
$scope
.
selection_text
))
{
// change the status of an existing Ngram
// action from the menu of an existing Ngram
$scope
.
selection_text
.
category
=
category
;
$scope
.
selection_text
.
category
=
$rootScope
.
lists
[
listId
].
toLowerCase
();
// TODO deprecated
$scope
.
selection_text
.
level
=
level
;
$scope
.
selection_text
.
level
=
level
;
// delete from the current list
NgramHttpService
[
action
](
NgramHttpService
.
delete
({
{
'listId'
:
$scope
.
selection_text
.
list_id
,
'listId'
:
$rootScope
.
listId
,
'ngramId'
:
$scope
.
selection_text
.
uuid
'ngramId'
:
$scope
.
selection_text
.
uuid
},
}).
$promise
.
then
(
function
(
data
)
{
{
'annotation'
:
$scope
.
selection_text
}
// add to the new list
);
NgramHttpService
.
post
(
{
'listId'
:
listId
,
'ngramId'
:
$scope
.
selection_text
.
uuid
}
);
});
}
else
if
(
$scope
.
selection_text
.
trim
()
!==
""
)
{
}
else
if
(
$scope
.
selection_text
.
trim
()
!==
""
)
{
// new annotation from selection
// new annotation from selection
NgramHttpService
.
post
(
NgramHttpService
.
post
(
{
{
'listId'
:
$rootScope
.
listId
'listId'
:
listId
,
'ngramId'
:
'new'
},
},
{
'annotation'
:
{
'text'
:
$scope
.
selection_text
.
trim
()
,
'category'
:
category
,
'level'
:
level
}}
{
'annotation'
:
{
'text'
:
$scope
.
selection_text
.
trim
()}}
);
);
}
}
// hide selection highlighted text and the menu
// hide selection highlighted text and the menu
...
@@ -313,16 +326,17 @@
...
@@ -313,16 +326,17 @@
});
});
});
});
function
submitNewAnnotation
(
$event
,
inputEltId
,
category
)
{
function
submitNewAnnotation
(
$event
,
inputEltId
,
listId
)
{
if
(
$event
.
keyCode
!==
undefined
&&
$event
.
keyCode
!=
13
)
return
;
if
(
$event
.
keyCode
!==
undefined
&&
$event
.
keyCode
!=
13
)
return
;
var
value
=
$
(
inputEltId
).
val
().
trim
();
var
value
=
$
(
inputEltId
).
val
().
trim
();
if
(
value
===
""
)
return
;
if
(
value
===
""
)
return
;
NgramHttpService
.
post
(
NgramHttpService
.
post
(
{
{
'listId'
:
$rootScope
.
listId
'listId'
:
listId
,
'ngramId'
:
'new'
},
},
{
'annotation'
:
{
'text'
:
value
,
'category'
:
category
,
'level'
:
'local'
}},
{
'annotation'
:
{
'text'
:
value
}},
function
(
data
)
{
function
(
data
)
{
// on success
// on success
if
(
data
)
{
if
(
data
)
{
...
...
annotations/static/annotations/http.js
View file @
e8590680
...
@@ -47,7 +47,7 @@
...
@@ -47,7 +47,7 @@
window
.
ANNOTATION_API_URL
+
'lists/:listId/ngrams/:ngramId/'
,
window
.
ANNOTATION_API_URL
+
'lists/:listId/ngrams/:ngramId/'
,
{
{
listId
:
'@listId'
,
listId
:
'@listId'
,
ngramId
:
'@ngramI
D
'
ngramId
:
'@ngramI
d
'
},
},
{
{
post
:
{
post
:
{
...
...
annotations/static/annotations/keyword_tpl.html
View file @
e8590680
<span
ng-if=
"keyword.category == 'miamlist'"
ng-click=
'onDeleteClick()'
class=
"delete-keyword"
data-keyword-id=
"{
{keyword.uuid}}"
data-keyword-text=
"{{keyword.text}
}"
data-keyword-category=
"miamlist"
>
×
</span>
<span
ng-if=
"keyword.category == 'miamlist'"
ng-click=
'onDeleteClick()'
class=
"delete-keyword"
data-keyword-id=
"{
[{keyword.uuid}]}"
data-keyword-text=
"{[{keyword.text}]
}"
data-keyword-category=
"miamlist"
>
×
</span>
<a
ng-if=
"keyword.category == 'miamlist'"
href=
"#"
data-toggle=
"tooltip"
class=
"keyword miamword"
>
{
{keyword.text}
}
</a>
<a
ng-if=
"keyword.category == 'miamlist'"
href=
"#"
data-toggle=
"tooltip"
class=
"keyword miamword"
>
{
[{keyword.text}]
}
</a>
<span
ng-if=
"keyword.category == 'stoplist'"
ng-click=
'onDeleteClick()'
class=
"delete-keyword"
data-keyword-id=
"{
{keyword.uuid}}"
data-keyword-text=
"{{keyword.text}
}"
data-keyword-category=
"stoplist"
>
×
</span>
<span
ng-if=
"keyword.category == 'stoplist'"
ng-click=
'onDeleteClick()'
class=
"delete-keyword"
data-keyword-id=
"{
[{keyword.uuid}]}"
data-keyword-text=
"{[{keyword.text}]
}"
data-keyword-category=
"stoplist"
>
×
</span>
<a
ng-if=
"keyword.category == 'stoplist'"
href=
"#"
data-toggle=
"tooltip"
class=
"keyword stopword"
>
{
{keyword.text}
}
</a>
<a
ng-if=
"keyword.category == 'stoplist'"
href=
"#"
data-toggle=
"tooltip"
class=
"keyword stopword"
>
{
[{keyword.text}]
}
</a>
<span
class=
"occurrences"
data-keyword-id=
"{
{keyword.uuid}}"
>
{{keyword.occurrences}
}
</span>
<span
class=
"occurrences"
data-keyword-id=
"{
[{keyword.uuid}]}"
>
{[{keyword.occurrences}]
}
</span>
annotations/static/annotations/selection_tpl.html
View file @
e8590680
<ul
class=
"noselection"
>
<ul
class=
"noselection"
>
<li>
{
{level}}
<span
ng-if=
"category !== null"
>
{{category}
}
</span></li>
<li>
{
[{level}]}
<span
ng-if=
"category !== null"
>
{[{category}]
}
</span></li>
<li
class=
"miamword"
ng-if=
"local_miamlist === true"
ng-click=
"onClick($event, 'post', '
miamlist
', 'local')"
>
add to miam-list
</li>
<li
class=
"miamword"
ng-if=
"local_miamlist === true"
ng-click=
"onClick($event, 'post', '
{[{ miamListId }]}
', 'local')"
>
add to miam-list
</li>
<li
class=
"miamword"
ng-if=
"local_miamlist === false"
ng-click=
"onClick($event, 'delete', '
miamlist
', 'local')"
>
remove from miam-list
</li>
<li
class=
"miamword"
ng-if=
"local_miamlist === false"
ng-click=
"onClick($event, 'delete', '
{[{ miamListId }]}
', 'local')"
>
remove from miam-list
</li>
<li
class=
"stopword"
ng-if=
"local_stoplist === true"
ng-click=
"onClick($event, 'post', '
stoplist
', 'local')"
>
add to local stop-list
</li>
<li
class=
"stopword"
ng-if=
"local_stoplist === true"
ng-click=
"onClick($event, 'post', '
{[{ stopListId }]}
', 'local')"
>
add to local stop-list
</li>
<li
class=
"stopword"
ng-if=
"local_stoplist === false"
ng-click=
"onClick($event, 'delete', '
stoplist
', 'local')"
>
remove from local stop-list
</li>
<li
class=
"stopword"
ng-if=
"local_stoplist === false"
ng-click=
"onClick($event, 'delete', '
{[{ stopListId }]}
', 'local')"
>
remove from local stop-list
</li>
<li
class=
"stopword"
ng-if=
"global_stoplist === true"
ng-click=
"onClick($event, 'post', 'stoplist', 'global')"
>
add to global stop-list
</li>
<
!--<
li class="stopword" ng-if="global_stoplist === true" ng-click="onClick($event, 'post', 'stoplist', 'global')">add to global stop-list</li>
<li
class=
"stopword"
ng-if=
"global_stoplist === false"
ng-click=
"onClick($event, 'delete', 'stoplist', 'global')"
>
remove from global stop-list
</li>
<li class="stopword" ng-if="global_stoplist === false" ng-click="onClick($event, 'delete', 'stoplist', 'global')">remove from global stop-list</li>
-->
</ul>
</ul>
annotations/urls.py
View file @
e8590680
...
@@ -5,5 +5,5 @@ from annotations import views
...
@@ -5,5 +5,5 @@ from annotations import views
urlpatterns
=
patterns
(
''
,
urlpatterns
=
patterns
(
''
,
url
(
r'^document/(?P<doc_id>[0-9]+)$'
,
views
.
Document
.
as_view
()),
# document view
url
(
r'^document/(?P<doc_id>[0-9]+)$'
,
views
.
Document
.
as_view
()),
# document view
url
(
r'^corpus/(?P<corpus_id>[0-9]+)/document/(?P<doc_id>[0-9]+)$'
,
views
.
NgramList
.
as_view
()),
# the list associated with an ngram
url
(
r'^corpus/(?P<corpus_id>[0-9]+)/document/(?P<doc_id>[0-9]+)$'
,
views
.
NgramList
.
as_view
()),
# the list associated with an ngram
url
(
r'^lists/(?P<list_id>[0-9]+)/ngrams
(?:/(?P<ngram_id>[0-9]+)
)?$'
,
views
.
Ngram
.
as_view
()),
#
url
(
r'^lists/(?P<list_id>[0-9]+)/ngrams
/(?P<ngram_id>[0-9]+|new
)?$'
,
views
.
Ngram
.
as_view
()),
#
)
)
annotations/views.py
View file @
e8590680
...
@@ -9,6 +9,7 @@ from django.contrib.auth.decorators import login_required
...
@@ -9,6 +9,7 @@ from django.contrib.auth.decorators import login_required
from
rest_framework.views
import
APIView
from
rest_framework.views
import
APIView
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
from
rest_framework.renderers
import
JSONRenderer
from
rest_framework.renderers
import
JSONRenderer
from
rest_framework.exceptions
import
APIException
from
node.models
import
Node
from
node.models
import
Node
from
gargantext_web.db
import
*
from
gargantext_web.db
import
*
...
@@ -40,7 +41,7 @@ class NgramList(APIView):
...
@@ -40,7 +41,7 @@ class NgramList(APIView):
for
list_type
in
[
'MiamList'
,
'StopList'
]:
for
list_type
in
[
'MiamList'
,
'StopList'
]:
list_id
=
list
()
list_id
=
list
()
list_id
=
listIds
(
user_id
=
request
.
user
.
id
,
corpus_id
=
int
(
corpus_id
),
typeList
=
list_type
)
list_id
=
listIds
(
user_id
=
request
.
user
.
id
,
corpus_id
=
int
(
corpus_id
),
typeList
=
list_type
)
lists
[
list_type
]
=
int
(
list_id
[
0
][
0
])
lists
[
"
%
s"
%
list_id
[
0
][
0
]]
=
list_type
# ngrams of list_id of corpus_id:
# ngrams of list_id of corpus_id:
doc_ngram_list
=
listNgramIds
(
corpus_id
=
corpus_id
,
doc_id
=
doc_id
,
user_id
=
request
.
user
.
id
)
doc_ngram_list
=
listNgramIds
(
corpus_id
=
corpus_id
,
doc_id
=
doc_id
,
user_id
=
request
.
user
.
id
)
...
@@ -67,13 +68,27 @@ class Ngram(APIView):
...
@@ -67,13 +68,27 @@ class Ngram(APIView):
"""
"""
Add a ngram in a list
Add a ngram in a list
"""
"""
ngramList
(
do
=
'add'
,
ngram_ids
=
[
ngram_id
],
list_id
=
list_id
)
ngram_dict
=
json
.
loads
(
request
.
POST
.
get
(
'annotation'
))
if
ngram_id
==
'new'
:
ngram_dict
=
json
.
loads
(
request
.
POST
.
get
(
'annotation'
))
results
=
ngramList
(
'create'
,
list_id
,
ngram_ids
=
[
ngram_dict
[
'text'
]])
else
:
results
=
ngramList
(
'add'
,
list_id
,
ngram_ids
=
[
ngram_id
])
return
Response
([{
'uuid'
:
ngram_id
,
'text'
:
ngram_text
,
'occurrences'
:
ngram_occurrences
,
'list_id'
:
list_id
,
}
for
ngram_id
,
ngram_text
,
ngram_occurrences
in
results
])
def
delete
(
self
,
request
,
list_id
,
ngram_id
):
def
delete
(
self
,
request
,
list_id
,
ngram_id
):
"""
"""
Remov
e a ngram from a list
Delet
e a ngram from a list
"""
"""
ngramList
(
do
=
'del'
,
ngram_ids
=
[
ngram_id
],
list_id
=
list_id
)
return
Response
({
'delete'
:
{
'
%
s'
%
ngram_id
:
ngramList
(
do
=
'del'
,
ngram_ids
=
[
ngram_id
],
list_id
=
list_id
)}})
class
Document
(
APIView
):
class
Document
(
APIView
):
...
...
gargantext_web/settings.py
View file @
e8590680
...
@@ -192,7 +192,6 @@ LOGIN_URL = '/auth/'
...
@@ -192,7 +192,6 @@ LOGIN_URL = '/auth/'
GRAPPELLI_ADMIN_TITLE
=
"Gargantext"
GRAPPELLI_ADMIN_TITLE
=
"Gargantext"
if
DEBUG
is
True
or
'GARGANTEXT_DEBUG'
in
os
.
environ
:
if
DEBUG
is
True
or
'GARGANTEXT_DEBUG'
in
os
.
environ
:
DEBUG
=
True
try
:
try
:
from
gargantext_web.local_settings
import
*
from
gargantext_web.local_settings
import
*
except
ImportError
:
except
ImportError
:
...
...
ngram/lists.py
View file @
e8590680
...
@@ -115,7 +115,7 @@ def listNgramIds(list_id=None, typeList=None,
...
@@ -115,7 +115,7 @@ def listNgramIds(list_id=None, typeList=None,
return
(
query
.
all
())
return
(
query
.
all
())
def
ngramList
(
do
=
None
,
ngram_ids
=
None
,
list_id
=
None
)
:
def
ngramList
(
do
,
list_id
,
ngram_ids
=
None
)
:
'''
'''
ngramList :: ([Int], Int, String) -> Bool
ngramList :: ([Int], Int, String) -> Bool
Do (delete | add) [ngram_id] (from | to) the list_id
Do (delete | add) [ngram_id] (from | to) the list_id
...
@@ -125,43 +125,45 @@ def ngramList(do=None, ngram_ids=None, list_id=None) :
...
@@ -125,43 +125,45 @@ def ngramList(do=None, ngram_ids=None, list_id=None) :
ngram_id = [Int] : list of Ngrams id (Ngrams.id)
ngram_id = [Int] : list of Ngrams id (Ngrams.id)
list_id = Int : list id (Node.id)
list_id = Int : list id (Node.id)
'''
'''
if
ngram_ids
is
None
:
results
=
[]
raise
Exception
(
'Need at least one ngram id in ngram_ids'
)
if
do
==
'create'
:
if
do
is
None
or
list_id
is
None
:
terms
=
copy
(
ngram_ids
)
raise
Exception
(
'Need more options: do, ngram_id, list_id'
)
ngram_ids
=
[]
for
ngram_term
in
terms
:
# TODO set the language correctly
ngram
=
Ngram
.
objects
.
get_or_create
(
terms
=
ngram_term
,
n
=
len
(
terms
.
split
()),
language
=
'en'
)
ngram_ids
+=
[
ngram
.
id
]
# TODO there should not be a try/except here, let the code crash as soon as possible
try
:
try
:
# node_type_id = (session.query(Node.type_id)
# .filter(Node.id == list_id)
# .first()
# )
for
ngram_id
in
ngram_ids
:
for
ngram_id
in
ngram_ids
:
# F
irst we test to know if ngram exist in database already
# F
etch the ngram from database
#ngram = (session.query(Ngram
).filter(Ngram.id == ngram_id).first()
ngram
=
session
.
query
(
Ngram
.
id
,
Ngram
.
terms
,
func
.
count
()
)
.
filter
(
Ngram
.
id
==
ngram_id
)
.
first
()
# Need to be optimized with list of ids
# Need to be optimized with list of ids
node_ngram
=
(
session
.
query
(
NodeNgram
)
node_ngram
=
(
session
.
query
(
NodeNgram
)
.
filter
(
NodeNgram
.
ngram_id
==
ngram_id
)
.
filter
(
NodeNgram
.
ngram_id
==
ngram_id
)
.
filter
(
NodeNgram
.
node_id
==
list_id
)
.
filter
(
NodeNgram
.
node_id
==
list_id
)
.
first
()
.
first
()
)
)
# create NodeNgram if does not exists
if
node_ngram
is
None
:
if
node_ngram
is
None
:
node_ngram
=
NodeNgram
(
node_id
=
list_id
,
node_ngram
=
NodeNgram
(
node_id
=
list_id
,
ngram_id
=
ngram_id
,
ngram_id
=
ngram_id
,
weight
=
1
)
weight
=
1
)
if
do
==
'add'
:
if
do
==
'add'
:
session
.
add
(
node_ngram
)
session
.
add
(
node_ngram
)
results
+=
[
ngram
]
elif
do
==
'del'
:
elif
do
==
'del'
:
session
.
delete
(
node_ngram
)
session
.
delete
(
node_ngram
)
session
.
commit
()
session
.
commit
()
return
(
True
)
return
(
results
)
except
:
except
Exception
as
exc
:
PrintException
()
PrintException
()
return
(
False
)
raise
exc
# Some functions to manage automatically the lists
# Some functions to manage automatically the lists
...
...
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