Search in sources :

Example 1 with KeywordPersister

use of com.graphaware.nlp.persistence.persisters.KeywordPersister in project neo4j-nlp by graphaware.

the class TextRankPersister method persistKeywords.

public void persistKeywords(Map<String, Keyword> results, Node annotatedText) {
    List<String> printKeywords = new ArrayList<>();
    KeywordPersister persister = NLPManager.getInstance().getPersister(Keyword.class);
    persister.setLabel(keywordLabel);
    results.entrySet().stream().forEach(en -> {
        // check keyword consistency
        if (en.getKey().split("_").length > 2) {
            LOG.warn("Tag " + en.getKey() + " has more than 1 underscore symbols, newly created " + keywordLabel.name() + " node might be wrong.");
        }
        Node newNode = persister.persist(en.getValue(), en.getKey(), String.valueOf(System.currentTimeMillis()));
        if (newNode != null) {
            // LOG.info("New node has labels: " + iterableToList(newNode.getLabels()).stream().map(l -> l.name()).collect(Collectors.joining(", ")));
            Relationship rel = mergeRelationship(annotatedText, newNode);
            rel.setProperty("count_exactMatch", en.getValue().getExactMatchCount());
            rel.setProperty("count", en.getValue().getTotalCount());
            rel.setProperty("relevance", en.getValue().getRelevance());
        }
        printKeywords.add(en.getKey().split("_")[0]);
    });
    LOG.debug("--- TextRank results: \n  " + printKeywords.stream().collect(Collectors.joining("\n  ")));
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) ArrayList(java.util.ArrayList) KeywordPersister(com.graphaware.nlp.persistence.persisters.KeywordPersister)

Example 2 with KeywordPersister

use of com.graphaware.nlp.persistence.persisters.KeywordPersister in project neo4j-nlp by graphaware.

the class TextRank method peristKeyword.

private void peristKeyword(Map<String, Keyword> results, Node annotatedText) {
    LOG.info("--- Results: ");
    KeywordPersister persister = NLPManager.getInstance().getPersister(Keyword.class);
    persister.setLabel(keywordLabel);
    results.entrySet().stream().forEach(en -> {
        // check keyword consistency
        if (en.getKey().split("_").length > 2) {
            LOG.warn("Tag " + en.getKey() + " has more than 1 underscore symbols, newly created " + keywordLabel.name() + " node might be wrong.");
        }
        Node newNode = persister.persist(en.getValue(), en.getKey(), String.valueOf(System.currentTimeMillis()));
        if (newNode != null) {
            // LOG.info("New node has labels: " + iterableToList(newNode.getLabels()).stream().map(l -> l.name()).collect(Collectors.joining(", ")));
            Relationship rel = mergeRelationship(annotatedText, newNode);
            rel.setProperty("count_exactMatch", en.getValue().getExactMatchCount());
            rel.setProperty("count", en.getValue().getTotalCount());
            rel.setProperty("relevance", en.getValue().getRelevance());
        }
        LOG.info(en.getKey().split("_")[0]);
    });
}
Also used : KeywordPersister(com.graphaware.nlp.persistence.persisters.KeywordPersister)

Aggregations

KeywordPersister (com.graphaware.nlp.persistence.persisters.KeywordPersister)2 ArrayList (java.util.ArrayList)1 Node (org.neo4j.graphdb.Node)1 Relationship (org.neo4j.graphdb.Relationship)1