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
c70206a2
Commit
c70206a2
authored
Jun 15, 2015
by
Mathieu Rodic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[BUG] adding ngrams to stop- or miamlist now works from the interface
parent
86c021ef
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
21 deletions
+49
-21
lists.py
analysis/lists.py
+13
-1
app.js
annotations/static/annotations/app.js
+4
-3
http.js
annotations/static/annotations/http.js
+3
-3
urls.py
annotations/urls.py
+1
-1
views.py
annotations/views.py
+28
-13
No files found.
analysis/lists.py
View file @
c70206a2
...
...
@@ -65,6 +65,18 @@ class WeightedMatrix:
"""
pass
def
__mul__
(
self
,
other
):
if
isinstance
(
other
,
Translations
):
result
=
WeightedMatrix
()
for
key1
,
key2_value
in
self
.
items
.
items
():
for
key2
,
value
in
self
.
items
:
result
.
items
[
other
.
items
.
get
(
key
,
key
)
]
=
value
else
:
raise
TypeError
return
result
class
UnweightedList
:
...
...
@@ -181,7 +193,7 @@ class WeightedList:
for
key
,
value
in
self
.
items
:
result
.
items
[
other
.
items
.
get
(
key
,
key
)
]
=
value
]
+
=
value
else
:
raise
TypeError
return
result
...
...
annotations/static/annotations/app.js
View file @
c70206a2
...
...
@@ -204,11 +204,12 @@
// new annotation from selection
NgramHttpService
.
post
(
{
'listId'
:
listId
,
'ngramId'
:
'new'
'listId'
:
listId
},
{
'annotation'
:
{
'text'
:
$scope
.
selection_text
.
trim
()}}
);
).
$promise
.
then
(
function
(
data
)
{
$rootScope
.
annotations
.
push
(
data
);
});
}
// hide selection highlighted text and the menu
$
(
".text-panel"
).
removeClass
(
"selection"
);
...
...
annotations/static/annotations/http.js
View file @
c70206a2
...
...
@@ -49,15 +49,15 @@
*/
http
.
factory
(
'NgramHttpService'
,
function
(
$resource
)
{
return
$resource
(
window
.
ANNOTATION_API_URL
+
'lists/:listId/ngrams/:ngramId
/
'
,
window
.
ANNOTATION_API_URL
+
'lists/:listId/ngrams/:ngramId'
,
{
listId
:
'@listId'
,
ngramId
:
'@
ngramI
d'
ngramId
:
'@
i
d'
},
{
post
:
{
method
:
'POST'
,
params
:
{
'listId'
:
'@listId'
,
'ngramId'
:
'
@ngramId
'
}
params
:
{
'listId'
:
'@listId'
,
'ngramId'
:
''
}
},
delete
:
{
method
:
'DELETE'
,
...
...
annotations/urls.py
View file @
c70206a2
...
...
@@ -5,5 +5,5 @@ from annotations import views
urlpatterns
=
patterns
(
''
,
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'^lists/(?P<list_id>[0-9]+)/ngrams
/(?P<ngram_id>[new0-9]+)
$'
,
views
.
NgramEdit
.
as_view
()),
#
url
(
r'^lists/(?P<list_id>[0-9]+)/ngrams
(?:/(?P<ngram_id>[0-9]+))?
$'
,
views
.
NgramEdit
.
as_view
()),
#
)
annotations/views.py
View file @
c70206a2
...
...
@@ -73,19 +73,34 @@ class NgramEdit(APIView):
"""
Add a ngram in a list
"""
# TODO if Ngram is in miam-list, and adding it to stop-list, then remove it from the previous list
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
])
# TODO - if Ngram is in miam-list, and adding it to stop-list,
# then remove it from the previous list
list_id
=
int
(
list_id
)
# format the ngram's text
ngram_text
=
request
.
data
.
get
(
'annotation'
,
{})
.
get
(
'text'
,
None
)
ngram_text
=
ngram_text
.
strip
()
.
lower
()
ngram_text
=
' '
.
join
(
ngram_text
.
split
())
# retrieve the ngram's id
ngram
=
session
.
query
(
Ngram
)
.
filter
(
Ngram
.
terms
==
ngram_text
)
.
first
()
if
ngram
is
None
:
ngram
=
Ngram
(
n
=
len
(
ngram_text
.
split
()),
terms
=
ngram_text
)
session
.
add
(
ngram
)
session
.
commit
()
ngram_id
=
ngram
.
id
# add the ngram to the list if not already done
node_ngram
=
session
.
query
(
Node_Ngram
)
.
filter
(
Node_Ngram
.
node_id
==
list_id
)
.
filter
(
Node_Ngram
.
ngram_id
==
ngram_id
)
.
first
()
if
node_ngram
is
None
:
node_ngram
=
Node_Ngram
(
node_id
=
list_id
,
ngram_id
=
ngram_id
,
weight
=
1.0
)
session
.
add
(
node_ngram
)
session
.
commit
()
ngram_occurrences
=
node_ngram
.
weight
# return the response
return
Response
({
'uuid'
:
ngram_id
,
'text'
:
ngram_text
,
'occurrences'
:
ngram_occurrences
,
'list_id'
:
list_id
,
})
def
delete
(
self
,
request
,
list_id
,
ngram_id
):
"""
...
...
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