Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jythonforjava和TextBlob_Java_Ascii_Jython_Textblob - Fatal编程技术网

jythonforjava和TextBlob

jythonforjava和TextBlob,java,ascii,jython,textblob,Java,Ascii,Jython,Textblob,我目前正在从事一个与python集成的Java项目。 为此,我使用以下软件包和ide: 月蚀 Jython 2.7.0 TextBlob v0.10.0-dev 以下是我的java代码片段: PythonInterpreter interpreter = new PythonInterpreter(); interpreter.execfile("AnSoMiaPy/analyser/test1.py"); PyObject translated_

我目前正在从事一个与python集成的Java项目。 为此,我使用以下软件包和ide:

月蚀 Jython 2.7.0 TextBlob v0.10.0-dev

以下是我的java代码片段:

        PythonInterpreter interpreter = new PythonInterpreter();
        interpreter.execfile("AnSoMiaPy/analyser/test1.py");
        PyObject translated_text = interpreter.get("translated_text");
        interpreter.close();
        System.out.println("translated_text: " + translated_text.toString());
python代码也相当简单

        #!/usr/bin/python
        # -*- coding: UTF-8 -*-
        from textblob import TextBlob
        import sys
        reload(sys)
        sys.setdefaultencoding("utf-8")

        text = '''
        The titular threat of The Blob has always struck me as the ultimate             movie
        monster: an insatiably hungry, amoeba-like mass able to penetrate
        virtually any safeguard, capable of--as a doomed doctor chillingly
        describes it--"assimilating flesh on contact.
        Snide comparisons to gelatin be damned, it's a concept with the most
        devastating of potential consequences, not unlike the grey goo scenario
        proposed by technological theorists fearful of
        artificial intelligence run rampant.
        '''
        blob = TextBlob(text)
        blob.noun_phrases   # WordList(['titular threat', 'blob',
                #            'ultimate movie monster',
                #            'amoeba-like mass', ...])

        for sentence in blob.sentences:
        print(sentence.sentiment.polarity)
        # 0.060
        # -0.341

        translated_text = blob.translate(to="de")
        print(translated_text)
        print blob.sentiment.polarity
当我执行python代码时,我得到了我所期望的:

0.06 -0.341666666667 这是一部名为《伊默·格施拉根》的终极电影 怪物:艾因·乌内斯·里奇·亨格里格,德拉格的阿莫贝纳蒂奇·马斯,祖德赫德林根 事实上,这是一个非常重要的问题 这是一个很好的例子。 阿伯弗利奇·维格利什·维达姆特·塞恩(verdammt sein)是麻省理工学院(mit)的一名工程师 莫格里琴·福根的父亲是一位名叫施密尔·塞纳里奥的父亲 杜尔奇技术理论公司fürchten vorgeschlagen 昆斯特利希·因利根茨·乌切恩。 -0.159091

但是,当我使用jython调用python脚本时,得到了以下结果:

0.0 0 这是一部名为《伊默·格施拉根》的终极电影 怪物:艾因·乌内斯·里奇·亨格里格,德拉格的阿莫贝纳蒂奇·马斯,祖德赫德林根 事实上,这是一个非常重要的问题 这是一个很好的例子。 阿伯弗利奇·维格利什·维达姆特·塞恩(verdammt sein)是麻省理工学院(mit)的一名工程师 莫格里琴·福根的父亲是一位名叫施密尔·塞纳里奥的父亲 杜尔奇技术理论公司fürchten vorgeschlagen 昆斯特利希·因利根茨·乌切恩。 0 翻译文本:TextBlob(“密歇根州最后一部电影《伊默·格施拉根》) 怪物:艾因努内斯·特里奇·亨格里格(EinunersÃ?ttlich hungrig),是德拉格的贝纳蒂奇·马斯(benartige Masse),祖杜克林根(zu Durchringen) 这是一个很好的解决方案,因为它需要大量的资金 这是一个很好的例子。 他是麻省理工学院的一名学生 格里琴·弗尔根(glichen Folgen)的作品,作者是施梅内尔·塞纳里奥(Schmere Szenario) durch Technologies Theoretiker fürchten vorgeschlagen künstliche Intelligenz wuchern。”)

polarity突然变为0,在java中访问并打印转换后的变量后,ascii编码看起来有点奇怪


有人遇到过类似的问题吗?

我遇到过同样的问题。你找到解决方案了吗?我遇到过同样的问题。你找到解决方案了吗?