Git Product home page Git Product logo

Comments (4)

sergey-tihon avatar sergey-tihon commented on May 25, 2024

Sorry, I cannot open link https://prntscr.com/n5rfid
Can you please post code here ?
It may depends on what model you are trying to deserialize. Please specify Nuget package that you use (with version) and what model do you use (ideally, URL where you download it from)

from stanford.nlp.net.

AscanioB avatar AscanioB commented on May 25, 2024

Code below, error at: pipeline = new StanfordCoreNLP(props);

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using java.util.prefs;
using edu.stanford.nlp.ling;
using edu.stanford.nlp.pipeline;
using edu.stanford.nlp.util;
using edu.stanford.nlp.trees;
using edu.stanford.nlp.sentiment;
using edu.stanford.nlp.neural.rnn;
using edu.stanford.nlp.neural;
using org.ejml.simple;
using System.IO;

namespace Ascanio_Bajada_Thesis
{
    public class SentimentAnalyzer
    {
        StanfordCoreNLP pipeline;

        public void Initialize()
        {
            var jarRoot = @"..\..\..\..\Thesis\packages\stanford-corenlp-full-2018-02-27\models";

            java.util.Properties props = new java.util.Properties();

            props.setProperty("pos.model", "pos-tagger\\english-left3words-distsim.tagger");
            props.setProperty("ner.model", "ner\\classifiers\\english.all.3class.distsim.crf.ser.gz");
            props.setProperty("ner.useSUTime", "false");
            props.setProperty("ner.applyFineGrained", "0");
            props.setProperty("parse.model", "lexparser\\englishPCFG.ser.gz");
            props.setProperty("sentiment.model", "sentiment\\sentiment.ser.gz");
            props.setProperty("dcoref.demonym", "dcoref\\demonyms.txt");
            props.setProperty("dcoref.states", "dcoref\\state-abbreviations.txt");
            props.setProperty("dcoref.animate", "dcoref\\animate.unigrams.txt");
            props.setProperty("dcoref.inanimate", "dcoref\\inanimate.unigrams.txt");
            props.setProperty("dcoref.big.gender.number", "dcoref\\gender.map.ser.gz");
            props.setProperty("dcoref.countries", "dcoref\\countries");
            props.setProperty("dcoref.states.provinces", "dcoref\\statesandprovinces");
            props.setProperty("dcoref.singleton.model", "dcoref\\singleton.predictor.ser");
            props.setProperty("dcoref.language", "en");
            props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, sentiment");
            props.setProperty("dcoref.algorithm", "statistical");

            // build pipeline
            var curDir = Environment.CurrentDirectory;
            Directory.SetCurrentDirectory(jarRoot);

            pipeline = new StanfordCoreNLP(props);

            Directory.SetCurrentDirectory(curDir);
        }

        public SentimentResult GetSentimentResult(string text)
        {
            Initialize();

            SentimentClassification classification = new SentimentClassification();
            SentimentResult sentimentResult = new SentimentResult();

            if (text != null && text.Length > 0)
            {
                Annotation annotation = pipeline.process(text);

                var sentences = annotation.get(new CoreAnnotations.SentencesAnnotation().getClass()) as ArrayList;

                foreach (CoreMap sentence in sentences)
                {
                    Tree tree = (Tree)sentence.get(typeof(SentimentCoreAnnotations.SentimentAnnotatedTree));
                    int sentiment = RNNCoreAnnotations.getPredictedClass(tree);

                    SimpleMatrix simpleMatrix = RNNCoreAnnotations.getPredictions(tree);

                    classification.setVeryNegative((int)Math.Round(simpleMatrix.get(0) * 100d));
                    classification.setNegative((int)Math.Round(simpleMatrix.get(1) * 100d));
                    classification.setNeutral((int)Math.Round(simpleMatrix.get(2) * 100d));
                    classification.setPositive((int)Math.Round(simpleMatrix.get(3) * 100d));
                    classification.setVeryPositive((int)Math.Round(simpleMatrix.get(4) * 100d));

                    string setimentType = (string)sentence.get(typeof(SentimentCoreAnnotations.SentimentClass));

                    sentimentResult.setSentimentType(setimentType);
                    sentimentResult.setSentimentClass(classification);
                    sentimentResult.setSentimentScore(RNNCoreAnnotations.getPredictedClass(tree));
                }
            }
            return sentimentResult;
        }
    }
}

Nuget package: Stanford.NLP.CoreNLP 3.9.1
Model: stanford-english-corenlp-2018-02-27-models (I've also tried with the 2018-10-05, v3.9.2) downloaded from https://stanfordnlp.github.io/CoreNLP/history.html
Re-hosted images to imgur

Furthermore I've also tried extracting the stanford-corenlp-3.9.1.jar file, moving the SimpleTensor.class to the correct directory (under edu.stanford.nlp.neural.rnn), archiving into .jar and replacing the old one but the Object Browser still found it under the neural directory.

from stanford.nlp.net.

arcontechnologies avatar arcontechnologies commented on May 25, 2024

Used Nuget package: Stanford.NLP.CoreNLP 3.9.1

Hi ,
I have the same issue . It throws error at :

var pipeline = new StanfordCoreNLP(props)

I saw that workaround exist in java : https://github.com/stanfordnlp/CoreNLP/issues/715
But how do we tackle "dependencies" in .Net as Maven / POM.xml tool doesn't exist ?

Any idea, insight ?

Thanks for your feedback

from stanford.nlp.net.

sergey-tihon avatar sergey-tihon commented on May 25, 2024

Close as an old issue

from stanford.nlp.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.