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

Clear plugin #493

Closed
lukeyt opened this issue Jun 15, 2018 · 8 comments
Closed

Clear plugin #493

lukeyt opened this issue Jun 15, 2018 · 8 comments

Comments

@lukeyt
Copy link

lukeyt commented Jun 15, 2018

There does not seem to be any way to clear a previously loaded plugin. For instance if I use the example:

`let plugin = {
words: {
'trex': 'Dinosaur'
},
tags: {
Dinosaur: {
isA: 'Animal'
}
}
};
nlp.plugin(plugin);
let doc = nlp('i saw a HUUUUGE trex');

doc.match('#Dinosaur').out('normal')// 'trex'`

There doesn't seem to be any way to unload 'plugin', so that

doc.match('#Dinosaur').out('normal')

Will always return 'trex'. Am I missing something? I want to be able to switch out a plugin and load another one without reloading the browser window.

@spencermountain
Copy link
Owner

hey @lukeyt yeah, you can do this with .clone(), but it's a little awkward.

let nlp2 = nlp.clone();
nlp.plugin({
  words: {
    trex: 'plugin'
  }
});
nlp('trex').debug();
nlp2('trex').debug();

cheers

@lukeyt
Copy link
Author

lukeyt commented Jun 19, 2018

Great - thank you @spencermountain - I will give it a go!

@lukeyt
Copy link
Author

lukeyt commented Jun 19, 2018

I have tried this - however its not quite working as I expected after all -

var nlp2 = nlp.clone();

nlp2.plugin({
words: {
trex: 'plugin'
}
});

will error with nlp2.plugin is not a function. What I had hoped was that I could use the approach above to clone nlp each time I wanted to load a different plugin, discarding the clone each time. But it seems clone does not clone the methods (or at least the plugin method)?

@spencermountain
Copy link
Owner

yeah, rats. i was afraid of that.

check out this issue, where someone reloads the library using require-reload.

i can look at cleaning up the library clone stuff, but it's behind a backlog right now.

@playground
Copy link

Is there a solution to clear nlp plugin?

@spencermountain
Copy link
Owner

hey @playground yes, .clone() should work as expected now:
https://observablehq.com/@spencermountain/compromise-constructor-methods
cheers

@playground
Copy link

playground commented Mar 10, 2020

so how would you do this?
nlp.plugin(plugin1) has the origin content, would like to clear it and reload it with new content such as nlp.plugin(plugin2)

Ah, I was still on version 11, just upgraded to the latest 13.1.1 but getting nlp.plugin is not a function.

@spencermountain
Copy link
Owner

yes, please read the v12 release notes and the documentation for .clone()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants