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

System.NullReferenceException during tokenization #1

Open
sdg002 opened this issue Sep 13, 2019 · 1 comment
Open

System.NullReferenceException during tokenization #1

sdg002 opened this issue Sep 13, 2019 · 1 comment

Comments

@sdg002
Copy link

sdg002 commented Sep 13, 2019

Hi All,
I am trying to get some very basic tokenization to work. I think I am not using the API properly because the method Tokenize is throwing System.NullReferenceException. Any suggestions?

My code

using CH = global::CherubNLP.Tokenize;

public string[] MyTokenize(string sentence)
{
           var options = new CH.TokenizationOptions
            {
                
            };
            var tokenizer = new CH.TokenizerFactory(
                                    options, 
                                    global::CherubNLP.SupportedLanguage.English);
            var tokens = tokenizer.Tokenize(sentence);
            string[] results = tokens.
                                    Where(tk=>tk.IsAlpha==true).
                                    Select(tk => tk.Text).ToArray();
            return results;
}
 

Thank you,
Sau

@sdg002
Copy link
Author

sdg002 commented Sep 13, 2019

Ok. I figured this out myself. I should be calling the GetTokenizer method of the factory and then invoke the method Tokenize.

            var options = new CH.TokenizationOptions
            {
                
            };
            var factory = new CH.TokenizerFactory(
                                    options, 
                                    global::CherubNLP.SupportedLanguage.English);
            var tokenizer = factory.GetTokenizer<CH.TreebankTokenizer>();
            var tokens = tokenizer.Tokenize(sentence,options);
            string[] results = tokens.
                                    Where(tk=>tk.IsAlpha==true).
                                    Select(tk => tk.Text).ToArray();
            return results;



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

1 participant