Search in sources :

Example 1 with TextRankRequest

use of com.graphaware.nlp.dsl.request.TextRankRequest in project neo4j-nlp by graphaware.

the class TextRankProcedure method summarizeText.

@Procedure(name = "ga.nlp.ml.textRank.summarize", mode = Mode.WRITE)
@Description("TextRank procedure")
public Stream<SingleResult> summarizeText(@Name("textRankRequest") Map<String, Object> textRankRequest) {
    try {
        TextRankRequest request = TextRankRequest.fromMap(textRankRequest);
        TextRankProcessor processor = (TextRankProcessor) getNLPManager().getExtension(TextRankProcessor.class);
        return Stream.of(processor.summarize(request));
    } catch (Exception e) {
        LOG.error("ERROR in TextRankSummarizer", e);
        throw new RuntimeException(e);
    }
}
Also used : TextRankProcessor(com.graphaware.nlp.ml.textrank.TextRankProcessor) TextRankRequest(com.graphaware.nlp.dsl.request.TextRankRequest) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Example 2 with TextRankRequest

use of com.graphaware.nlp.dsl.request.TextRankRequest in project neo4j-nlp by graphaware.

the class TextRankProcedure method computeTextRank.

@Procedure(name = "ga.nlp.ml.textRank.compute", mode = Mode.WRITE)
@Description("Keywords Extraction using TextRank algorithm ( without storage )")
public Stream<KeywordResult> computeTextRank(@Name("textRankRequest") Map<String, Object> textRankRequest) {
    try {
        TextRankRequest request = TextRankRequest.fromMap(textRankRequest);
        TextRankProcessor processor = (TextRankProcessor) getNLPManager().getExtension(TextRankProcessor.class);
        TextRankResult result = processor.compute(request);
        return result.getResult().values().stream().map(keyword -> {
            return new KeywordResult(keyword.getKeyword(), keyword.getRelevance());
        });
    } catch (Exception e) {
        LOG.error("Error during TextRank computation", e);
        throw new RuntimeException(e);
    }
}
Also used : TextRankResult(com.graphaware.nlp.ml.textrank.TextRankResult) TextRankProcessor(com.graphaware.nlp.ml.textrank.TextRankProcessor) TextRankRequest(com.graphaware.nlp.dsl.request.TextRankRequest) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Example 3 with TextRankRequest

use of com.graphaware.nlp.dsl.request.TextRankRequest in project neo4j-nlp by graphaware.

the class TextRankProcedure method computeAndStoreTextRank.

@Procedure(name = "ga.nlp.ml.textRank", mode = Mode.WRITE)
@Description("Keywords Extraction using TextRank algorithm (includes storage of result)")
public Stream<SingleResult> computeAndStoreTextRank(@Name("textRankRequest") Map<String, Object> textRankRequest) {
    try {
        TextRankRequest request = TextRankRequest.fromMap(textRankRequest);
        TextRankProcessor processor = (TextRankProcessor) getNLPManager().getExtension(TextRankProcessor.class);
        return Stream.of(processor.computeAndStore(request));
    } catch (Exception e) {
        LOG.error("ERROR in TextRank", e);
        throw new RuntimeException(e);
    }
}
Also used : TextRankProcessor(com.graphaware.nlp.ml.textrank.TextRankProcessor) TextRankRequest(com.graphaware.nlp.dsl.request.TextRankRequest) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Aggregations

TextRankRequest (com.graphaware.nlp.dsl.request.TextRankRequest)3 TextRankProcessor (com.graphaware.nlp.ml.textrank.TextRankProcessor)3 Description (org.neo4j.procedure.Description)3 Procedure (org.neo4j.procedure.Procedure)3 TextRankResult (com.graphaware.nlp.ml.textrank.TextRankResult)1