Search in sources :

Example 1 with TextRankProcessor

use of com.graphaware.nlp.ml.textrank.TextRankProcessor 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 TextRankProcessor

use of com.graphaware.nlp.ml.textrank.TextRankProcessor 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 TextRankProcessor

use of com.graphaware.nlp.ml.textrank.TextRankProcessor in project neo4j-nlp by graphaware.

the class TextRankProcedure method textRankPostprocess.

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

Example 4 with TextRankProcessor

use of com.graphaware.nlp.ml.textrank.TextRankProcessor 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

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