Search in sources :

Example 1 with Tag

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;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ArrayList(java.util.ArrayList) WebResource(com.sun.jersey.api.client.WebResource) Tag(com.graphaware.nlp.domain.Tag)

Example 2 with Tag

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;
}
Also used : Tag(com.graphaware.nlp.domain.Tag)

Example 3 with 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;
}
Also used : Tag(com.graphaware.nlp.domain.Tag)

Example 4 with 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;
}
Also used : Tag(com.graphaware.nlp.domain.Tag)

Example 5 with 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);
}
Also used : Tag(com.graphaware.nlp.domain.Tag) Sentence(com.graphaware.nlp.domain.Sentence)

Aggregations

Tag (com.graphaware.nlp.domain.Tag)20 Sentence (com.graphaware.nlp.domain.Sentence)9 AnnotatedText (com.graphaware.nlp.domain.AnnotatedText)8 TagUtils.newTag (com.graphaware.nlp.util.TagUtils.newTag)5 TestAnnotatedText (com.graphaware.nlp.util.TestAnnotatedText)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Node (org.neo4j.graphdb.Node)3 Cache (com.google.common.cache.Cache)2 CacheBuilder (com.google.common.cache.CacheBuilder)2 LoggerFactory (com.graphaware.common.log.LoggerFactory)2 TextProcessor (com.graphaware.nlp.processor.TextProcessor)2 TextUtils.removeApices (com.graphaware.nlp.util.TextUtils.removeApices)2 TextUtils.removeParenthesis (com.graphaware.nlp.util.TextUtils.removeParenthesis)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 WebResource (com.sun.jersey.api.client.WebResource)2 List (java.util.List)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 TimeUnit (java.util.concurrent.TimeUnit)2