Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
c2dc40ac
Commit
c2dc40ac
authored
Jan 14, 2022
by
Piotr Gawron
Browse files
unused method removed
parent
ecc31fd7
Changes
2
Hide whitespace changes
Inline
Side-by-side
annotation/src/main/java/lcsb/mapviewer/annotation/services/MeSHParser.java
View file @
c2dc40ac
package
lcsb.mapviewer.annotation.services
;
import
java.io.IOException
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
import
org.apache.commons.lang3.SerializationException
;
import
org.apache.http.HttpStatus
;
...
...
@@ -12,7 +16,11 @@ import org.w3c.dom.Node;
import
com.google.gson.Gson
;
import
lcsb.mapviewer.annotation.cache.*
;
import
lcsb.mapviewer.annotation.cache.CachableInterface
;
import
lcsb.mapviewer.annotation.cache.GeneralCacheInterface
;
import
lcsb.mapviewer.annotation.cache.SourceNotAvailable
;
import
lcsb.mapviewer.annotation.cache.WebPageDownloader
;
import
lcsb.mapviewer.annotation.cache.XmlSerializer
;
import
lcsb.mapviewer.annotation.data.MeSH
;
import
lcsb.mapviewer.annotation.services.annotators.AnnotatorException
;
import
lcsb.mapviewer.common.exception.InvalidArgumentException
;
...
...
@@ -60,7 +68,7 @@ public class MeSHParser extends CachableInterface implements IExternalService {
}
@Override
public
Object
refreshCacheQuery
(
Object
query
)
throws
SourceNotAvailable
{
public
Object
refreshCacheQuery
(
final
Object
query
)
throws
SourceNotAvailable
{
Object
result
=
null
;
try
{
if
(
query
instanceof
String
)
{
...
...
@@ -92,7 +100,7 @@ public class MeSHParser extends CachableInterface implements IExternalService {
}
@Override
protected
void
setWebPageDownloader
(
WebPageDownloader
webPageDownloader
)
{
protected
void
setWebPageDownloader
(
final
WebPageDownloader
webPageDownloader
)
{
super
.
setWebPageDownloader
(
webPageDownloader
);
}
...
...
@@ -103,7 +111,7 @@ public class MeSHParser extends CachableInterface implements IExternalService {
* @throws AnnotatorException
* thrown when there is a problem with accessing mesh database
*/
public
MeSH
getMeSH
(
MiriamData
meshID
)
throws
AnnotatorException
{
public
MeSH
getMeSH
(
final
MiriamData
meshID
)
throws
AnnotatorException
{
if
(
meshID
==
null
||
meshID
.
getResource
()
==
null
)
{
throw
new
InvalidArgumentException
(
"mesh cannot be null "
);
}
...
...
@@ -142,7 +150,7 @@ public class MeSHParser extends CachableInterface implements IExternalService {
* id as miriam data.
* @return return the object.
*/
public
String
getIdentifier
(
MiriamData
meshID
)
{
public
String
getIdentifier
(
final
MiriamData
meshID
)
{
return
MESH_PREFIX
+
meshID
.
getResource
();
}
...
...
@@ -155,7 +163,7 @@ public class MeSHParser extends CachableInterface implements IExternalService {
* @throws AnnotatorException
* thrown when there is a problem with accessing mesh db
*/
private
MeSH
getMeSHByIdFromDB
(
MiriamData
meshID
)
throws
IOException
{
private
MeSH
getMeSHByIdFromDB
(
final
MiriamData
meshID
)
throws
IOException
{
try
{
MeSH
result
=
new
MeSH
();
String
page
=
getWebPageContent
(
URL_MESH_DATABASE
+
meshID
.
getResource
());
...
...
@@ -163,7 +171,7 @@ public class MeSHParser extends CachableInterface implements IExternalService {
Gson
gson
=
new
Gson
();
Map
<?,
?>
gsonObject
=
new
HashMap
<
String
,
Object
>();
gsonObject
=
(
Map
<?,
?>)
gson
.
fromJson
(
page
,
gsonObject
.
getClass
());
gsonObject
=
gson
.
fromJson
(
page
,
gsonObject
.
getClass
());
Set
<
String
>
synonyms
=
getSynonyms
(
gsonObject
);
String
name
=
getName
(
gsonObject
);
String
description
=
getDescription
(
gsonObject
);
...
...
@@ -191,7 +199,7 @@ public class MeSHParser extends CachableInterface implements IExternalService {
* gson to process
* @return name of {@link MeSH} entry
*/
private
String
getName
(
Map
<?,
?>
gsonObject
)
{
private
String
getName
(
final
Map
<?,
?>
gsonObject
)
{
Map
<?,
?>
descriptorTag
=
(
Map
<?,
?>)
gsonObject
.
get
(
"DescriptorName"
);
if
(
descriptorTag
==
null
)
{
descriptorTag
=
(
Map
<?,
?>)
gsonObject
.
get
(
"SupplementalRecordName"
);
...
...
@@ -206,7 +214,7 @@ public class MeSHParser extends CachableInterface implements IExternalService {
* gson to process
* @return id of {@link MeSH} entry
*/
private
String
getId
(
Map
<?,
?>
gsonObject
)
{
private
String
getId
(
final
Map
<?,
?>
gsonObject
)
{
Map
<?,
?>
descriptorTag
=
(
Map
<?,
?>)
gsonObject
.
get
(
"DescriptorUI"
);
if
(
descriptorTag
==
null
)
{
descriptorTag
=
(
Map
<?,
?>)
gsonObject
.
get
(
"SupplementalRecordUI"
);
...
...
@@ -221,7 +229,7 @@ public class MeSHParser extends CachableInterface implements IExternalService {
* gson to process
* @return description of {@link MeSH} entry
*/
private
String
getDescription
(
Map
<?,
?>
gsonObject
)
{
private
String
getDescription
(
final
Map
<?,
?>
gsonObject
)
{
Map
<?,
?>
concepts
=
(
Map
<?,
?>)
gsonObject
.
get
(
"_generated"
);
return
(
String
)
concepts
.
get
(
"PreferredConceptScopeNote"
);
}
...
...
@@ -233,7 +241,7 @@ public class MeSHParser extends CachableInterface implements IExternalService {
* gson to process
* @return synonyms of {@link MeSH} entry
*/
private
Set
<
String
>
getSynonyms
(
Map
<?,
?>
gsonObject
)
{
private
Set
<
String
>
getSynonyms
(
final
Map
<?,
?>
gsonObject
)
{
Set
<
String
>
synonyms
=
new
HashSet
<>();
Map
<?,
?>
concepts
=
(
Map
<?,
?>)
gsonObject
.
get
(
"ConceptList"
);
ArrayList
<?>
conceptList
=
(
ArrayList
<?>)
concepts
.
get
(
"Concept"
);
...
...
@@ -280,33 +288,14 @@ public class MeSHParser extends CachableInterface implements IExternalService {
* @throws AnnotatorException
* thrown when there is problem with accessing mesh db
*/
public
boolean
isValidMeshId
(
MiriamData
meshId
)
throws
AnnotatorException
{
public
boolean
isValidMeshId
(
final
MiriamData
meshId
)
throws
AnnotatorException
{
if
(
meshId
==
null
)
{
return
false
;
}
return
getMeSH
(
meshId
)
!=
null
;
}
public
List
<
MeSH
>
getMeshBySynonym
(
String
synonym
)
throws
AnnotatorException
{
try
{
List
<
MeSH
>
result
=
new
ArrayList
<>();
String
page
=
getWebPageContent
(
URL_SEARCH_BY_SYNONYM
+
synonym
);
Gson
gson
=
new
Gson
();
Map
<?,
?>
gsonObject
=
new
HashMap
<
String
,
Object
>();
gsonObject
=
(
Map
<?,
?>)
gson
.
fromJson
(
page
,
gsonObject
.
getClass
());
Set
<
MiriamData
>
synonyms
=
getIdsBySynonymQuery
(
gsonObject
);
for
(
MiriamData
meshID
:
synonyms
)
{
result
.
add
(
getMeSH
(
meshID
));
}
return
result
;
}
catch
(
IOException
e
)
{
throw
new
AnnotatorException
(
e
);
}
}
private
Set
<
MiriamData
>
getIdsBySynonymQuery
(
Map
<?,
?>
gsonObject
)
{
private
Set
<
MiriamData
>
getIdsBySynonymQuery
(
final
Map
<?,
?>
gsonObject
)
{
Set
<
MiriamData
>
result
=
new
HashSet
<>();
Map
<?,
?>
hits
=
(
Map
<?,
?>)
gsonObject
.
get
(
"hits"
);
ArrayList
<?>
hitsList
=
(
ArrayList
<?>)
hits
.
get
(
"hits"
);
...
...
annotation/src/test/java/lcsb/mapviewer/annotation/services/MeSHParserTest.java
View file @
c2dc40ac
package
lcsb.mapviewer.annotation.services
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyString
;
import
static
org
.
mockito
.
ArgumentMatchers
.
nullable
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
java.io.IOException
;
import
java.util.List
;
import
org.apache.http.HttpStatus
;
import
org.apache.logging.log4j.LogManager
;
...
...
@@ -16,7 +19,9 @@ import org.mockito.Mockito;
import
org.springframework.beans.factory.annotation.Autowired
;
import
lcsb.mapviewer.annotation.AnnotationTestFunctions
;
import
lcsb.mapviewer.annotation.cache.*
;
import
lcsb.mapviewer.annotation.cache.GeneralCacheInterface
;
import
lcsb.mapviewer.annotation.cache.SourceNotAvailable
;
import
lcsb.mapviewer.annotation.cache.WebPageDownloader
;
import
lcsb.mapviewer.annotation.data.MeSH
;
import
lcsb.mapviewer.annotation.services.annotators.AnnotatorException
;
import
lcsb.mapviewer.common.exception.InvalidArgumentException
;
...
...
@@ -42,15 +47,6 @@ public class MeSHParserTest extends AnnotationTestFunctions {
assertTrue
(
mesh
.
getSynonyms
().
size
()
>
0
);
}
@Test
public
void
testGetMeshBySynonym
()
throws
Exception
{
String
synonym
=
"MPTP"
;
List
<
MeSH
>
result
=
meshParser
.
getMeshBySynonym
(
synonym
);
assertEquals
(
1
,
result
.
size
());
MeSH
mesh
=
result
.
get
(
0
);
assertTrue
(
mesh
.
getSynonyms
().
contains
(
synonym
));
}
@Test
public
void
testIsValidMesh
()
throws
Exception
{
MiriamData
meshID
=
new
MiriamData
(
MiriamType
.
MESH_2012
,
"D004298"
);
...
...
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