Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Text Mining Resources Hub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Carlos Vega
Text Mining Resources Hub
Commits
d5a331db
Commit
d5a331db
authored
5 years ago
by
Valentin Groues
Browse files
Options
Downloads
Patches
Plain Diff
add jensenlab implementation
parent
c7dccd1d
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
interface/TextMiningService.py
+2
-1
2 additions, 1 deletion
interface/TextMiningService.py
jensenlab-service/__init__.py
+4
-0
4 additions, 0 deletions
jensenlab-service/__init__.py
jensenlab-service/jensenLabService.py
+63
-0
63 additions, 0 deletions
jensenlab-service/jensenLabService.py
with
69 additions
and
1 deletion
interface/TextMiningService.py
+
2
−
1
View file @
d5a331db
from
abc
import
ABCMeta
,
abstractmethod
from
typing
import
List
from
models.publication
import
Publication
from
models.coocurrence
import
CoOccurrence
from
models.publication
import
Publication
class
TextMiningService
(
metaclass
=
ABCMeta
):
...
...
This diff is collapsed.
Click to expand it.
jensenlab-service/__init__.py
0 → 100644
+
4
−
0
View file @
d5a331db
import
logging
logger
=
logging
.
getLogger
(
__name__
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
jensenlab-service/jensenLabService.py
0 → 100644
+
63
−
0
View file @
d5a331db
import
json
import
logging
from
typing
import
List
import
requests
from
TextMiningService
import
TextMiningService
,
Publication
logger
=
logging
.
getLogger
(
__name__
)
class
JensenLabService
(
TextMiningService
):
BASE_URL
=
"
https://api.jensenlab.org
"
MENTION_URL
=
BASE_URL
+
"
/Mentions?type={}&id={}&limit={}&format=json
"
IDS_MAPPING
=
{
"
CID
"
:
-
1
,
"
BTO
"
:
-
25
,
"
DOID
"
:
-
26
,
}
def
__init__
(
self
):
super
().
__init__
(
"
JensenLabService
"
,
"
Text-Mining api available at api.jensenlab.org
"
)
def
get_mentions
(
self
,
entities
:
List
,
limit
:
int
=
20
)
->
List
[
Publication
]:
entities_and_types
=
self
.
guess_types_for_entities
(
entities
)
publications_ids
=
[]
for
(
entity
,
entity_type
)
in
entities_and_types
:
publications_ids
.
append
(
self
.
get_mentions_for_entity
(
entity
,
entity_type
,
limit
))
publications_ids_intersection
=
set
.
intersection
(
*
publications_ids
)
return
[
Publication
(
pm_id
=
pid
)
for
pid
in
publications_ids_intersection
]
def
get_co_occurrences
(
self
,
entity
:
str
)
->
List
[
str
]:
pass
@staticmethod
def
guess_types_for_entities
(
entities
):
results
=
[]
for
entity
in
entities
:
entity_type
=
JensenLabService
.
guess_type_for_entity
(
entity
)
results
.
append
((
entity
,
entity_type
))
return
results
@staticmethod
def
guess_type_for_entity
(
entity
):
for
prefix
,
entity_type
in
JensenLabService
.
IDS_MAPPING
.
items
():
if
entity
.
startswith
(
prefix
):
return
entity_type
return
-
1
def
get_mentions_for_entity
(
self
,
entity
,
entity_type
,
limit
):
url_mentions
=
JensenLabService
.
MENTION_URL
.
format
(
entity_type
,
entity
,
limit
)
results
=
requests
.
get
(
url_mentions
)
assert
results
.
ok
publications_string
=
results
.
content
.
decode
().
strip
().
replace
(
'
True
'
,
'
true
'
).
replace
(
'
False
'
,
'
false
'
)
publications_list
,
has_more
=
json
.
loads
(
publications_string
)
return
set
(
publications_list
)
if
__name__
==
'
__main__
'
:
text_mining_service
=
JensenLabService
()
print
(
"
Using service {}
"
.
format
(
text_mining_service
.
name
))
publications
=
text_mining_service
.
get_mentions
([
"
DOID:10652
"
,
"
DOID:10654
"
],
limit
=
1000000
)
print
(
"
,
"
.
join
([
p
.
pm_id
for
p
in
publications
]))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment