Python jpype.JClass() Examples

The following are 12 code examples of jpype.JClass(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module jpype , or try the search function .
Example #1
Source File: plot_compressed_f1.py    From pyhanlp with Apache License 2.0 6 votes vote down vote up
def train_evaluate(ratios):
    if not os.path.isfile(msr_model):
        model = CWSTrainer().train(msr_train, msr_train, msr_model, 0, 10, 8).getModel()  # 训练模型
    else:
        model = JClass('com.hankcs.hanlp.model.perceptron.model.LinearModel')(msr_model)
    pre = None
    scores = []
    for c in ratios:
        if pre:
            print('以压缩比{}压缩模型中...'.format(c))
            model.compress(1 - (1 - c) / pre, 0)
        pre = 1 - c
        result = CWSEvaluator.evaluate(PerceptronLexicalAnalyzer(model).enableCustomDictionary(False),
                                       msr_test, msr_output, msr_gold, msr_dict)
        # scores.append(result.F1)
        scores.append(float(str(result).split()[2][3:]))
    return scores 
Example #2
Source File: sutime.py    From python-sutime with GNU General Public License v3.0 6 votes vote down vote up
def __init__(
        self,
        jars=None,
        jvm_started=False,
        mark_time_ranges=False,
        include_range=False,
        jvm_flags=None,
        language="english",
    ):
        """Initializes SUTime.
        """
        self.jars = jars if jars is not None else []
        self._check_language_model_dependency(language.lower())

        if not jvm_started and not jpype.isJVMStarted():
            self._start_jvm(jvm_flags)

        if not jpype.isThreadAttachedToJVM():
            jpype.attachThreadToJVM()
        wrapper = jpype.JClass("edu.stanford.nlp.python.SUTimeWrapper")
        self._sutime = wrapper(mark_time_ranges, include_range, language) 
Example #3
Source File: duckling.py    From python-duckling with Apache License 2.0 5 votes vote down vote up
def __init__(self,
                 jvm_started=False,
                 parse_datetime=False,
                 minimum_heap_size='128m',
                 maximum_heap_size='2048m'):
        """Initializes Duckling.
        """

        self.parse_datetime = parse_datetime
        self._is_loaded = False
        self._lock = threading.Lock()

        if not jvm_started:
            self._classpath = self._create_classpath()
            self._start_jvm(minimum_heap_size, maximum_heap_size)

        try:
            # make it thread-safe
            if threading.activeCount() > 1:
                if not jpype.isThreadAttachedToJVM():
                    jpype.attachThreadToJVM()
            self._lock.acquire()

            self.clojure = jpype.JClass('clojure.java.api.Clojure')
            # require the duckling Clojure lib
            require = self.clojure.var("clojure.core", "require")
            require.invoke(self.clojure.read("duckling.core"))
        finally:
            self._lock.release() 
Example #4
Source File: test_duckling.py    From python-duckling with Apache License 2.0 5 votes vote down vote up
def clojure():
    return jpype.JClass('clojure.java.api.Clojure') 
Example #5
Source File: test_duckling.py    From python-duckling with Apache License 2.0 5 votes vote down vote up
def java_symbol():
    return jpype.JClass('clojure.lang.Symbol') 
Example #6
Source File: test_duckling.py    From python-duckling with Apache License 2.0 5 votes vote down vote up
def java_boolean():
    return jpype.JClass('java.lang.Boolean') 
Example #7
Source File: test_duckling.py    From python-duckling with Apache License 2.0 5 votes vote down vote up
def java_string():
    return jpype.JClass('java.lang.String') 
Example #8
Source File: test_duckling.py    From python-duckling with Apache License 2.0 5 votes vote down vote up
def java_int():
    return jpype.JClass('java.lang.Integer') 
Example #9
Source File: test_duckling.py    From python-duckling with Apache License 2.0 5 votes vote down vote up
def java_arrays():
    return jpype.JClass('java.util.Arrays') 
Example #10
Source File: test_duckling.py    From python-duckling with Apache License 2.0 5 votes vote down vote up
def java_persistant_array_map():
    return jpype.JClass('clojure.lang.PersistentArrayMap') 
Example #11
Source File: test_duckling.py    From python-duckling with Apache License 2.0 5 votes vote down vote up
def java_map_entry():
    return jpype.JClass('clojure.lang.MapEntry') 
Example #12
Source File: test_duckling.py    From python-duckling with Apache License 2.0 5 votes vote down vote up
def java_keyword():
    return jpype.JClass('clojure.lang.Keyword')