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
38f314b9
Commit
38f314b9
authored
Nov 17, 2015
by
PkSM3
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'unstable' of
ssh://delanoe.org:1979/gargantext
into samuel
parents
ea082fb2
c7aa5060
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
72 deletions
+11
-72
ngrams.py
rest_v1_0/ngrams.py
+11
-72
No files found.
rest_v1_0/ngrams.py
View file @
38f314b9
...
@@ -76,76 +76,6 @@ from rest_framework.decorators import api_view
...
@@ -76,76 +76,6 @@ from rest_framework.decorators import api_view
# TODO how to secure REST ?
# TODO how to secure REST ?
def
get_occtfidf
(
ngrams
,
user_id
,
corpus_id
,
list_name
):
ngram_ids
=
{}
corpus
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
corpus_id
)
.
first
()
nodes_ngrams
=
session
.
query
(
Ngram
)
.
filter
(
Ngram
.
id
.
in_
(
ngrams
)
)
.
all
()
for
ngram
in
nodes_ngrams
:
ngram_ids
[
ngram
.
id
]
=
{
"id"
:
ngram
.
id
,
"name"
:
ngram
.
terms
,
"scores"
:
{}
}
# [ = = = = = = Get Uniq_Occs = = = = = = ]
myamlist
=
session
.
query
(
Node
)
.
filter
(
Node
.
user_id
==
user_id
,
Node
.
parent_id
==
corpus_id
,
Node
.
type_id
==
cache
.
NodeType
[
list_name
]
.
id
)
.
first
()
Miam
=
aliased
(
NodeNgram
)
ngrams_occs
=
(
session
.
query
(
NodeNgram
.
ngram_id
,
func
.
sum
(
NodeNgram
.
weight
))
.
join
(
Node
,
Node
.
id
==
NodeNgram
.
node_id
)
.
join
(
Miam
,
Miam
.
ngram_id
==
NodeNgram
.
ngram_id
)
.
filter
(
Node
.
parent_id
==
corpus_id
,
Node
.
type_id
==
cache
.
NodeType
[
'Document'
]
.
id
)
.
filter
(
Miam
.
node_id
==
myamlist
.
id
)
.
group_by
(
NodeNgram
.
ngram_id
)
.
all
()
)
for
ngram
in
ngrams_occs
:
try
:
ngram_ids
[
ngram
[
0
]
][
"scores"
][
"occ_uniq"
]
=
ngram
[
1
]
except
:
pass
for
i
in
ngram_ids
:
if
"occ_uniq"
not
in
ngram_ids
[
i
][
"scores"
]:
ngram_ids
[
i
][
"scores"
][
"occ_uniq"
]
=
1
# [ = = = = = = / Get Uniq_Occs = = = = = = ]
group_by
=
[]
results
=
[
'id'
,
'terms'
]
ngrams_query
=
(
session
.
query
(
Ngram
.
id
,
Ngram
.
terms
)
.
join
(
Node_Ngram
,
Node_Ngram
.
ngram_id
==
Ngram
.
id
)
.
join
(
Node
,
Node
.
id
==
Node_Ngram
.
node_id
)
)
Tfidf
=
aliased
(
NodeNodeNgram
)
tfidf_id
=
get_or_create_node
(
nodetype
=
'Tfidf (global)'
,
corpus
=
corpus
)
.
id
ngrams_query
=
(
ngrams_query
.
add_column
(
Tfidf
.
score
.
label
(
'tfidf'
))
.
join
(
Tfidf
,
Tfidf
.
ngram_id
==
Ngram
.
id
)
.
filter
(
Tfidf
.
nodex_id
==
tfidf_id
)
)
group_by
.
append
(
Tfidf
.
score
)
results
.
append
(
'tfidf'
)
ngrams_query
=
(
ngrams_query
.
filter
(
Node
.
parent_id
==
corpus_id
)
.
group_by
(
Ngram
.
id
,
Ngram
.
terms
,
*
group_by
)
)
TheList
=
aliased
(
NodeNgram
)
list_id
=
get_or_create_node
(
nodetype
=
list_name
,
corpus
=
corpus
)
.
id
ngrams_query
=
(
ngrams_query
.
join
(
TheList
,
TheList
.
ngram_id
==
Ngram
.
id
)
.
filter
(
TheList
.
node_id
==
list_id
)
)
for
ngram
in
ngrams_query
:
try
:
ngram_ids
[
ngram
[
0
]
][
"scores"
][
"tfidf"
]
=
ngram
[
2
]
except
:
pass
for
i
in
ngram_ids
:
if
"tfidf"
not
in
ngram_ids
[
i
][
"scores"
]:
ngram_ids
[
i
][
"scores"
][
"tfidf"
]
=
0.01
return
ngram_ids
class
List
(
APIView
):
class
List
(
APIView
):
...
@@ -168,7 +98,8 @@ class List(APIView):
...
@@ -168,7 +98,8 @@ class List(APIView):
class
Ngrams
(
APIView
):
class
Ngrams
(
APIView
):
'''
'''
REST application to manage ngrams
REST application to manage ngrams
Example :
http://localhost:8000/api/node/1444485/ngrams?format=json&score=tfidf,occurrences
'''
'''
def
get
(
self
,
request
,
node_id
):
def
get
(
self
,
request
,
node_id
):
# query ngrams
# query ngrams
...
@@ -203,6 +134,10 @@ class Ngrams(APIView):
...
@@ -203,6 +134,10 @@ class Ngrams(APIView):
# )
# )
# for i in ngrams_query:
# for i in ngrams_query:
# print(i)
# print(i)
if
'occurrences'
in
the_score
:
occurrences
=
func
.
sum
(
Node_Ngram
.
weight
)
.
label
(
'occurrences'
)
ngrams_query
=
(
ngrams_query
.
add_column
(
occurrences
))
results
.
append
(
'occurences'
)
if
'tfidf'
in
the_score
:
if
'tfidf'
in
the_score
:
Tfidf
=
aliased
(
NodeNodeNgram
)
Tfidf
=
aliased
(
NodeNodeNgram
)
...
@@ -235,7 +170,9 @@ class Ngrams(APIView):
...
@@ -235,7 +170,9 @@ class Ngrams(APIView):
results
.
append
(
'specificity'
)
results
.
append
(
'specificity'
)
order_query
=
request
.
GET
.
get
(
'order'
,
False
)
order_query
=
request
.
GET
.
get
(
'order'
,
False
)
if
order_query
==
'cvalue'
:
if
order_query
==
'occurrences'
:
ngrams_query
=
ngrams_query
.
order_by
(
desc
(
occurrences
))
elif
order_query
==
'cvalue'
:
ngrams_query
=
ngrams_query
.
order_by
(
desc
(
Cvalue
.
score
))
ngrams_query
=
ngrams_query
.
order_by
(
desc
(
Cvalue
.
score
))
elif
order_query
==
'tfidf'
:
elif
order_query
==
'tfidf'
:
ngrams_query
=
ngrams_query
.
order_by
(
desc
(
Tfidf
.
score
))
ngrams_query
=
ngrams_query
.
order_by
(
desc
(
Tfidf
.
score
))
...
@@ -309,6 +246,8 @@ class Ngrams(APIView):
...
@@ -309,6 +246,8 @@ class Ngrams(APIView):
except
:
pass
except
:
pass
try
:
info
[
"terms"
]
=
ngram
.
terms
try
:
info
[
"terms"
]
=
ngram
.
terms
except
:
pass
except
:
pass
try
:
info
[
"occurrences"
]
=
ngram
.
occurrences
except
:
pass
try
:
info
[
"tfidf"
]
=
ngram
.
tfidf
try
:
info
[
"tfidf"
]
=
ngram
.
tfidf
except
:
pass
except
:
pass
try
:
info
[
"cvalue"
]
=
ngram
.
cvalue
try
:
info
[
"cvalue"
]
=
ngram
.
cvalue
...
...
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