Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use .melt_tagger several times #22

Open
JulienDrochon opened this issue Sep 4, 2019 · 1 comment
Open

Use .melt_tagger several times #22

JulienDrochon opened this issue Sep 4, 2019 · 1 comment
Labels
bug Something isn't working

Comments

@JulienDrochon
Copy link

Hello,

i use melt_tagger in a class. The sentence to analyze is sent with socketio

import spacy
import sys
import random
from spacy_lefff import LefffLemmatizer, POSTagger
import socketio

class SomeClass():
    def __init__(self):
        self.nlp = spacy.load('fr')
        self.pos = POSTagger()  # comments in console
        self.french_lemmatizer = LefffLemmatizer(
            after_melt=True, default=False)
        self.nlp.add_pipe(self.pos, name='pos', after='parser')
        self.nlp.add_pipe(self.french_lemmatizer, name='lefff', after='pos')

    def analyze(self, param1):
        self.doc = self.nlp(param1)
        for d in self.doc:
            print(d.text, d.pos_, d._.melt_tagger)

# --- Socket

sio = socketio.Client()

@sio.on('connect', namespace='/test')
def on_connect():
    print('--> connection established')


@sio.on('disconnect', namespace='/test')
def on_disconnect():
    print('--> disconnected from server')


@sio.on('myevent', namespace='/test')
def on_message(data):
    print(' Received message : ',  data['spoken'])
    obj1.analyze(data['spoken'])

sio.connect('http://localhost:7000', namespaces=['/test'])

obj1 = SomeClass()

sio.wait()

On the first try with data[''spoken"] equals to 'les carottes et les radis sont des légumes',
the console prints :

 Received message : {'spoken': ' les carottes et les radis sont des légumes'}
2019-09-04 12:43:21,766 - spacy_lefff.melt_tagger - INFO -   TAGGER: POS Tagging...
les DET DET
carottes NOUN NC
et CCONJ CC
les DET DET
radis NOUN NC
sont AUX V
des DET DET
légumes NOUN NC

The next tries print in console :

Received message : {'spoken': ' les carottes et les radis sont des légumes'}
2019-09-04 12:43:27,007 - spacy_lefff.melt_tagger - INFO -   TAGGER: POS Tagging...
les DET None
carottes NOUN None
et CCONJ None
les DET None
radis NOUN None
sont AUX None
des DET None
légumes NOUN None

d.text, d.pos_ work on every request, melt_taggerdoesn't.

@sammous
Copy link
Owner

sammous commented Sep 20, 2019

Hi,
Probably comes from the use of socketio, I would have to investigate to exactly understand why.

@sammous sammous added the bug Something isn't working label Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants