use of com.graphaware.nlp.domain.Tag in project neo4j-nlp by graphaware.
the class MicrosoftConceptEnricher method getConcepts.
public List<Tag> getConcepts(Tag tag, int limit) {
final List<Tag> concepts = new ArrayList<>();
String param = tag.getLemma();
try {
param = URLEncoder.encode(tag.getLemma(), "UTF-8");
} catch (Exception e) {
//
return concepts;
}
String url = "https://concept.research.microsoft.com/api/Concept/ScoreByProb?instance=" + param + "&topK=" + limit;
WebResource resource = Client.create(cfg).resource(url);
ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).get(ClientResponse.class);
Map<String, Double> map = response.getEntity(Map.class);
map.keySet().stream().forEach(k -> {
Tag n = new Tag(cleanImportedConcept(k), "en");
tag.addParent("IS_RELATED_TO", n, map.get(k).floatValue(), ENRICHER_NAME);
concepts.add(n);
});
return concepts;
}
use of com.graphaware.nlp.domain.Tag in project neo4j-nlp by graphaware.
the class TagPersister method fromNode.
@Override
public Tag fromNode(Node node, Object... properties) {
checkNodeIsATag(node);
Tag tag = new Tag(String.valueOf(node.getProperty(configuration().getPropertyKeyFor(Properties.CONTENT_VALUE))), String.valueOf(node.getProperty(configuration().getPropertyKeyFor(Properties.LANGUAGE))));
String[] ne = (String[]) node.getProperty(configuration().getPropertyKeyFor(Properties.NAMED_ENTITY));
if (ne != null) {
tag.setNe(Arrays.asList(ne));
}
String[] pos = (String[]) node.getProperty(configuration().getPropertyKeyFor(Properties.PART_OF_SPEECH));
if (pos != null) {
tag.setPos(Arrays.asList(pos));
}
return tag;
}
use of com.graphaware.nlp.domain.Tag in project neo4j-nlp by graphaware.
the class TagUtils method newTag.
public static Tag newTag(String lemma, List<String> namedEntities, List<String> pos) {
Tag tag = new Tag(lemma, "en");
tag.setNe(namedEntities);
tag.setPos(pos);
return tag;
}
use of com.graphaware.nlp.domain.Tag in project neo4j-nlp by graphaware.
the class TagUtils method newTag.
public static Tag newTag(String lemma, String language, String namedEntity) {
Tag tag = new Tag(lemma, language);
tag.setNe(Collections.singletonList(namedEntity));
return tag;
}
use of com.graphaware.nlp.domain.Tag in project neo4j-nlp by graphaware.
the class TestAnnotatedText method assertTagWithLemma.
public void assertTagWithLemma(String value) {
boolean found = false;
for (Sentence sentence : annotatedText.getSentences()) {
for (Tag tag : sentence.getTags().values()) {
if (tag.getLemma().equals(value)) {
found = true;
break;
}
}
}
assertTrue(found);
}
Aggregations