-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix to edit rules handling, added stanza lemmatizer
- Loading branch information
1 parent
1abf423
commit ea23dfd
Showing
6 changed files
with
105 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Python.Runtime; | ||
|
||
namespace OpusCatMTEngine | ||
{ | ||
static class PythonNetHelper | ||
{ | ||
private static Dictionary<IsoLanguage, dynamic> LemmatizerScopes = new Dictionary<IsoLanguage, dynamic>(); | ||
|
||
internal static string Lemmatize(IsoLanguage lang, string input) | ||
{ | ||
using (Py.GIL()) | ||
{ | ||
if (!PythonNetHelper.LemmatizerScopes.ContainsKey(lang)) | ||
{ | ||
//Initialize the lemmatizer | ||
using (var moduleScope = Py.CreateScope()) | ||
{ | ||
moduleScope.Exec(OpusCatMTEngine.Properties.Resources.StanzaWrapperCode); | ||
// create a Python scope | ||
using (PyScope scope = Py.CreateScope()) | ||
{ | ||
scope.Import(moduleScope, "stanza_wrapper"); | ||
|
||
PythonNetHelper.LemmatizerScopes[lang] = scope.Eval<dynamic>( | ||
$"stanza_wrapper.StanzaWrapper('{lang.ShortestIsoCode}', processors='tokenize, pos, lemma, depparse')"); | ||
} | ||
} | ||
} | ||
|
||
return PythonNetHelper.LemmatizerScopes[lang].lemmatize(input); | ||
} | ||
} | ||
} | ||
} |