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
25d76875
Commit
25d76875
authored
May 10, 2016
by
delanoe
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'romain-refactoring' into refactoring
parents
06d0a25a
ff1b1634
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
87 additions
and
80 deletions
+87
-80
activelists.js
annotations/static/annotations/activelists.js
+7
-3
app.css
annotations/static/annotations/app.css
+2
-1
highlight.js
annotations/static/annotations/highlight.js
+51
-58
ngramlist.js
annotations/static/annotations/ngramlist.js
+12
-12
main.html
annotations/templates/annotations/main.html
+2
-2
views.py
annotations/views.py
+13
-4
No files found.
annotations/static/annotations/activelists.js
View file @
25d76875
...
...
@@ -10,10 +10,14 @@
$scope
.
activeListsChange
=
function
()
{
var
selected
=
$
(
'.selectpicker option:selected'
).
val
();
var
newActive
=
{};
$
(
'.selectpicker option:selected'
).
each
(
function
(
item
,
value
)
{
var
id
=
value
.
id
.
split
(
"---"
,
2
)[
1
];
newActive
[
id
]
=
value
.
value
;
$
(
'.selectpicker option:selected'
).
each
(
function
(
item
,
opt
)
{
// ex opt:
// <option id="list---748" value="MAINLIST">MAINLIST</option>
var
id
=
opt
.
id
.
split
(
"---"
,
2
)[
1
];
newActive
[
id
]
=
opt
.
value
;
});
// ex: {745: "MAINLIST", 748: "MAPLIST"}
$rootScope
.
activeLists
=
newActive
;
};
...
...
annotations/static/annotations/app.css
View file @
25d76875
...
...
@@ -9,7 +9,8 @@
.MAPLIST
{
color
:
black
;
/* green */
background-color
:
rgba
(
60
,
118
,
61
,
.7
);
background-color
:
rgba
(
23
,
255
,
189
,
.7
);
/* background-color: rgba(60, 118, 61, .7); */
cursor
:
pointer
;
}
...
...
annotations/static/annotations/highlight.js
View file @
25d76875
...
...
@@ -441,15 +441,12 @@
var
middlePattern
=
" "
;
var
endPattern
=
"(?:<
\
/span>)*)
\\
b"
;
console
.
log
(
"highlight annotations length: "
+
annotations
.
length
)
// hash of flags filled in first pass loop : (== did annotation i match ?)
var
isDisplayedIntraText
=
{};
var
sortedSizeAnnotations
=
lengthSort
(
annotations
,
"text"
),
extraNgramList
=
angular
.
copy
(
$rootScope
.
extraNgramList
);
console
.
log
(
"highlight annotations length: "
+
annotations
.
length
)
// reinitialize an empty list
extraNgramList
=
angular
.
forEach
(
extraNgramList
,
function
(
name
,
id
)
{
extraNgramList
[
id
]
=
[];
});
var
sortedSizeAnnotations
=
lengthSort
(
annotations
,
"text"
)
// rl: £dbg counters
var
i
=
0
;
...
...
@@ -506,6 +503,9 @@
var
nbMatches
=
matches
?
eltLongtext
.
match
(
myPattern
).
length
:
0
if
(
nbMatches
>
0
)
{
k
+=
nbMatches
;
// remember that this annotation.text matched
isDisplayedIntraText
[
annotation
.
uuid
]
=
annotation
l
++
;
// ------------------------------------------------------------
// ICI we update each time
...
...
@@ -549,81 +549,72 @@
// highlight anchors as html spans
// -------------------------------
angular
.
forEach
(
textMapping
,
function
(
text
,
eltId
)
{
angular
.
forEach
(
textMapping
,
function
(
text
Content
,
eltId
)
{
// console.log(anchorPattern)
if
(
text
)
{
if
(
text
Content
)
{
textMapping
[
eltId
]
=
replaceAnchorByTemplate
(
text
,
text
Content
,
annotation
,
template
,
anchorPattern
);
}
});
// rloth: for now let's show *all* ngrams of the active list
// in the left side
extraNgramList
[
annotation
.
list_id
]
=
extraNgramList
[
annotation
.
list_id
].
concat
(
annotation
);
});
// let's show just the ngrams that matched
// in the left side
var
sortedDisplayedKeys
=
Object
.
keys
(
isDisplayedIntraText
).
sort
()
// sorts on ngram_id
// new update ngramsInPanel
angular
.
forEach
(
sortedDisplayedKeys
,
function
(
id
)
{
var
the_annot
=
isDisplayedIntraText
[
id
]
;
var
the_list_id
=
the_annot
.
list_id
;
$rootScope
.
ngramsInPanel
[
the_list_id
].
push
(
the_annot
)
});
// debug
//console.warn("$rootScope.ngramsInPanel :")
//console.warn($rootScope.ngramsInPanel)
// update extraNgramList
$rootScope
.
extraNgramList
=
angular
.
forEach
(
extraNgramList
,
function
(
name
,
id
)
{
extraNgramList
[
id
]
=
lengthSort
(
extraNgramList
[
id
],
'text'
);
});
// return the object of element ID with the corresponding HTML
return
textMapping
;
}
/*
* main refresh
*/
$rootScope
.
refreshDisplay
=
function
()
{
console
.
log
(
"annotations.highlight.refreshDisplay()"
)
if
(
$rootScope
.
annotations
===
undefined
)
return
;
if
(
$rootScope
.
activeLists
===
undefined
)
return
;
if
(
_
.
keys
(
$rootScope
.
activeLists
).
length
===
0
)
return
;
// initialize extraNgramList
var
extraNgramList
=
{};
$rootScope
.
extraNgramList
=
angular
.
forEach
(
$rootScope
.
activeLists
,
function
(
name
,
id
)
{
this
[
id
]
=
[];
},
extraNgramList
);
$rootScope
.
extraNgramList
=
extraNgramList
;
// initialize ngramsInPanel
// ------------------------
// $rootScope.ngramsInPanel = {
// activelist1_id : [
// annotation_a,
// annotation_b,
// annotation_c
// ] ,
// activelist2_id : [
// annotation_x,
// annotation_y,
// annotation_z
// ] ,
// ....
// }
//
var
ngramsInPanel
=
{};
$rootScope
.
ngramsInPanel
=
angular
.
forEach
(
$rootScope
.
activeLists
,
function
(
name
,
list_id
)
{
this
[
list_id
]
=
[];
},
ngramsInPanel
);
$rootScope
.
ngramsInPanel
=
ngramsInPanel
;
/*
* Transform text into HTML with higlighted ngrams
* Transform text into HTML with higlighted ngrams
via compileNgramsHtml
*/
var
result
=
compileNgramsHtml
(
$rootScope
.
annotations
,
...
...
@@ -643,6 +634,8 @@
angular
.
element
(
elt
).
replaceWith
(
$compile
(
elt
)(
$rootScope
.
$new
(
true
)));
});
}
/*
* Listen changes on the ngram data
*/
...
...
annotations/static/annotations/ngramlist.js
View file @
25d76875
...
...
@@ -30,7 +30,7 @@
// (then used for left-side flatlist AND inline annots)
$rootScope
.
annotations
=
data
[
$rootScope
.
corpusId
.
toString
()][
$rootScope
.
docId
.
toString
()];
// TODO £NEW : lookup obj[list_id][term_text] = {terminfo}
// $rootScope.lookup =
// $rootScope.lookup =
$rootScope
.
refreshDisplay
();
},
function
(
data
)
{
...
...
@@ -49,7 +49,7 @@
annotationsAppNgramList
.
controller
(
'NgramListPaginationController'
,
[
'$scope'
,
'$rootScope'
,
function
(
$scope
,
$rootScope
)
{
$rootScope
.
$watchCollection
(
'
extraNgramList
'
,
function
(
newValue
,
oldValue
)
{
$rootScope
.
$watchCollection
(
'
ngramsInPanel
'
,
function
(
newValue
,
oldValue
)
{
$scope
.
currentListPage
=
0
;
$scope
.
pageSize
=
15
;
...
...
@@ -62,8 +62,8 @@
};
$scope
.
totalListPages
=
function
(
listId
)
{
if
(
$rootScope
.
extraNgramList
[
listId
]
===
undefined
)
return
0
;
return
Math
.
ceil
(
$rootScope
.
extraNgramList
[
listId
].
length
/
$scope
.
pageSize
);
if
(
$rootScope
.
ngramsInPanel
[
listId
]
===
undefined
)
return
0
;
return
Math
.
ceil
(
$rootScope
.
ngramsInPanel
[
listId
].
length
/
$scope
.
pageSize
);
};
});
}]);
...
...
@@ -93,12 +93,12 @@
var
value
=
angular
.
element
(
inputEltId
).
val
().
trim
();
if
(
value
===
""
)
return
;
// £TEST locally check if already in annotations NodeNgrams ------
// $rootScope.annotations = array of ngram objects like:
// {"list_id":805,"occurrences":2,"uuid":9386,"text":"petit échantillon"}
console
.
log
(
'looking for "'
+
value
+
'" in list:'
+
listId
)
var
already_in_list
=
false
;
angular
.
forEach
(
$rootScope
.
annotations
,
function
(
annot
,
i
)
{
...
...
@@ -112,7 +112,7 @@
);
if
(
already_in_list
)
{
return
;
}
// ---------------------------------------------------------------
// will check if there's a preexisting ngramId for this value
// TODO: if maplist => also add to miam
NgramHttpService
.
post
(
...
...
@@ -136,11 +136,11 @@
},
function
(
data
)
{
$rootScope
.
annotations
=
data
[
$rootScope
.
corpusId
.
toString
()][
$rootScope
.
docId
.
toString
()];
// TODO £NEW : lookup obj[list_id][term_text] = {terminfo}
// $rootScope.lookup =
// $rootScope.lookup =
$rootScope
.
refreshDisplay
();
},
function
(
data
)
{
...
...
annotations/templates/annotations/main.html
View file @
25d76875
...
...
@@ -32,12 +32,12 @@
</ul>
<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-if=
"
extraNgramList
[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}]}'
</div>
<ul
class=
"list-group words-list clearfix"
>
<li
ng-repeat=
"keyword in
extraNgramList
[listId] | startFrom:currentListPage * pageSize | limitTo:pageSize"
class=
"keyword-group-item"
>
<li
ng-repeat=
"keyword in
ngramsInPanel
[listId] | startFrom:currentListPage * pageSize | limitTo:pageSize"
class=
"keyword-group-item"
>
<div
ng-controller=
"NgramController"
keyword-template
class=
"keyword-container"
></div>
</li>
</ul>
...
...
annotations/views.py
View file @
25d76875
...
...
@@ -14,7 +14,7 @@ from rest_framework.authentication import SessionAuthentication, BasicAuthentica
# 2016-03-24: refactoring, new paths
from
gargantext.models.ngrams
import
Node
,
NodeNgram
,
Ngram
from
gargantext.util.db
import
session
from
gargantext.util.db
import
session
,
aliased
from
gargantext.util.db_cache
import
cache
from
gargantext.util.http
import
requires_auth
...
...
@@ -47,16 +47,25 @@ class NgramList(APIView):
doc_ngram_list
=
[]
lists
=
{}
corpus_nod
=
cache
.
Node
[
corpus_id
]
doc_nod
=
cache
.
Node
[
doc_id
]
scores_nod
=
corpus_nod
.
children
(
typename
=
"OCCURRENCES"
)
.
first
()
for
list_type
in
[
'MAINLIST'
,
'MAPLIST'
,
'STOPLIST'
]:
corpus_nod
=
cache
.
Node
[
corpus_id
]
list_nod
=
corpus_nod
.
children
(
typename
=
list_type
)
.
first
()
list_id
=
list_nod
.
id
lists
[
"
%
s"
%
list_id
]
=
list_type
ListsTable
=
aliased
(
NodeNgram
)
# doc_nod.ngrams iff we just need the occurrences in the doc (otherwise do manually)
q
=
doc_nod
.
ngrams
.
join
(
ListsTable
)
.
filter
(
ListsTable
.
node_id
==
list_id
)
# add to results
doc_ngram_list
+=
[(
obj
.
id
,
obj
.
terms
,
w
,
list_id
)
for
(
w
,
obj
)
in
list_nod
.
ngrams
.
all
()]
doc_ngram_list
+=
[(
obj
.
id
,
obj
.
terms
,
w
,
list_id
)
for
(
w
,
obj
)
in
q
.
all
()]
print
(
"annotations.views.NgramList.doc_ngram_list: "
,
doc_ngram_list
)
# debug
# print("annotations.views.NgramList.doc_ngram_list: ", doc_ngram_list)
data
=
{
'
%
s'
%
corpus_id
:
{
'
%
s'
%
doc_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