Beispiel #1
0
 public TaggedLemmas(TaggedLemmas other) : this(morphodita_csharpPINVOKE.new_TaggedLemmas__SWIG_1(TaggedLemmas.getCPtr(other)), true)
 {
     if (morphodita_csharpPINVOKE.SWIGPendingException.Pending)
     {
         throw morphodita_csharpPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Beispiel #2
0
    public static int Main(string[] args)
    {
        if (args.Length < 1) {
            Console.Error.WriteLine("Usage: RunMorphoCli tagger_file");
            return 1;
        }

        Console.Error.Write("Loading tagger: ");
        Tagger tagger = Tagger.load(args[0]);
        if (tagger == null) {
            Console.Error.WriteLine("Cannot load tagger from file '{0}'", args[0]);
            return 1;
        }
        Console.Error.WriteLine("done");

        Forms forms = new Forms();
        TaggedLemmas lemmas = new TaggedLemmas();
        TokenRanges tokens = new TokenRanges();
        Tokenizer tokenizer = tagger.newTokenizer();
        if (tokenizer == null) {
            Console.Error.WriteLine("No tokenizer is defined for the supplied model!");
            return 1;
        }

        XmlTextWriter xmlOut = new XmlTextWriter(Console.Out);
        for (bool not_eof = true; not_eof; ) {
            string line;
            StringBuilder textBuilder = new StringBuilder();

            // Read block
            while ((not_eof = (line = Console.In.ReadLine()) != null) && line.Length > 0) {
                textBuilder.Append(line).Append('\n');
            }
            if (not_eof) textBuilder.Append('\n');

            // Tokenize and tag
            string text = textBuilder.ToString();
            tokenizer.setText(text);
            int t = 0;
            while (tokenizer.nextSentence(forms, tokens)) {
                tagger.tag(forms, lemmas);

                for (int i = 0; i < lemmas.Count; i++) {
                    TaggedLemma lemma = lemmas[i];
                    int token_start = (int)tokens[i].start, token_length = (int)tokens[i].length;
                    xmlOut.WriteString(text.Substring(t, token_start - t));
                    if (i == 0) xmlOut.WriteStartElement("sentence");
                    xmlOut.WriteStartElement("token");
                    xmlOut.WriteAttributeString("lemma", lemma.lemma);
                    xmlOut.WriteAttributeString("tag", lemma.tag);
                    xmlOut.WriteString(text.Substring(token_start, token_length));
                    xmlOut.WriteEndElement();
                    if (i + 1 == lemmas.Count) xmlOut.WriteEndElement();
                    t = token_start + token_length;
                }
            }
            xmlOut.WriteString(text.Substring(t));
        }
        return 0;
    }
Beispiel #3
0
 public TaggedLemmasEnumerator(TaggedLemmas collection)
 {
     collectionRef = collection;
     currentIndex  = -1;
     currentObject = null;
     currentSize   = collectionRef.Count;
 }
 public virtual void convertAnalyzed(TaggedLemmas tagged_lemmas)
 {
     morphodita_csharpPINVOKE.TagsetConverter_convertAnalyzed(swigCPtr, TaggedLemmas.getCPtr(tagged_lemmas));
     if (morphodita_csharpPINVOKE.SWIGPendingException.Pending)
     {
         throw morphodita_csharpPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Beispiel #5
0
 public void tag(Forms forms, TaggedLemmas tags)
 {
     morphodita_csharpPINVOKE.Tagger_tag__SWIG_1(swigCPtr, Forms.getCPtr(forms), TaggedLemmas.getCPtr(tags));
     if (morphodita_csharpPINVOKE.SWIGPendingException.Pending)
     {
         throw morphodita_csharpPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Beispiel #6
0
 public void SetRange(int index, TaggedLemmas values)
 {
     morphodita_csharpPINVOKE.TaggedLemmas_SetRange(swigCPtr, index, TaggedLemmas.getCPtr(values));
     if (morphodita_csharpPINVOKE.SWIGPendingException.Pending)
     {
         throw morphodita_csharpPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Beispiel #7
0
        public virtual int analyze(string form, int guesser, TaggedLemmas lemmas)
        {
            int ret = morphodita_csharpPINVOKE.Morpho_analyze(swigCPtr, form, guesser, TaggedLemmas.getCPtr(lemmas));

            if (morphodita_csharpPINVOKE.SWIGPendingException.Pending)
            {
                throw morphodita_csharpPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Beispiel #8
0
        public static TaggedLemmas Repeat(TaggedLemma value, int count)
        {
            global::System.IntPtr cPtr = morphodita_csharpPINVOKE.TaggedLemmas_Repeat(TaggedLemma.getCPtr(value), count);
            TaggedLemmas          ret  = (cPtr == global::System.IntPtr.Zero) ? null : new TaggedLemmas(cPtr, true);

            if (morphodita_csharpPINVOKE.SWIGPendingException.Pending)
            {
                throw morphodita_csharpPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Beispiel #9
0
        public TaggedLemmas GetRange(int index, int count)
        {
            global::System.IntPtr cPtr = morphodita_csharpPINVOKE.TaggedLemmas_GetRange(swigCPtr, index, count);
            TaggedLemmas          ret  = (cPtr == global::System.IntPtr.Zero) ? null : new TaggedLemmas(cPtr, true);

            if (morphodita_csharpPINVOKE.SWIGPendingException.Pending)
            {
                throw morphodita_csharpPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Beispiel #10
0
    public static int Main(string[] args)
    {
        if (args.Length < 1)
        {
            Console.Error.WriteLine("Usage: RunMorphoCli dict_file");
            return(1);
        }

        Console.Error.Write("Loading dictionary: ");
        Morpho morpho = Morpho.load(args[0]);

        if (morpho == null)
        {
            Console.Error.WriteLine("Cannot load dictionary from file '{0}'", args[0]);
            return(1);
        }
        Console.Error.WriteLine("done");

        TaggedLemmas      lemmas      = new TaggedLemmas();
        TaggedLemmasForms lemmasForms = new TaggedLemmasForms();

        for (string line; (line = Console.In.ReadLine()) != null;)
        {
            string[] tokens = line.Split('\t');

            if (tokens.Length == 1) /* analyze */
            {
                int result = morpho.analyze(tokens[0], Morpho.GUESSER, lemmas);

                string guesser = result == Morpho.GUESSER ? "Guesser " : "";
                foreach (TaggedLemma lemma in lemmas)
                {
                    Console.WriteLine("{0}Lemma: {1} {2}", guesser, lemma.lemma, lemma.tag);
                }
            }
            else if (tokens.Length == 2)   /* generate */
            {
                int    result  = morpho.generate(tokens[0], tokens[1], Morpho.GUESSER, lemmasForms);
                String guesser = result == Morpho.GUESSER ? "Guesser " : "";
                foreach (TaggedLemmaForms lemmaForms in lemmasForms)
                {
                    Console.WriteLine("{0}Lemma: {1}", guesser, lemmaForms.lemma);
                    foreach (TaggedForm form in lemmaForms.forms)
                    {
                        Console.WriteLine("  {0} {1}", form.form, form.tag);
                    }
                }
            }
        }

        return(0);
    }
Beispiel #11
0
    public static int Main(string[] args)
    {
        if (args.Length < 1) {
            Console.Error.WriteLine("Usage: RunMorphoCli dict_file");
            return 1;
        }

        Console.Error.Write("Loading dictionary: ");
        Morpho morpho = Morpho.load(args[0]);
        if (morpho == null) {
            Console.Error.WriteLine("Cannot load dictionary from file '{0}'", args[0]);
            return 1;
        }
        Console.Error.WriteLine("done");

        TaggedLemmas lemmas = new TaggedLemmas();
        TaggedLemmasForms lemmasForms = new TaggedLemmasForms();
        for (string line; (line = Console.In.ReadLine()) != null; ) {
            string[] tokens = line.Split('\t');

            if (tokens.Length == 1) /* analyze */ {
                int result = morpho.analyze(tokens[0], Morpho.GUESSER, lemmas);

                string guesser = result == Morpho.GUESSER ? "Guesser " : "";
                foreach (TaggedLemma lemma in lemmas)
                    Console.WriteLine("{0}Lemma: {1} {2}", guesser, lemma.lemma, lemma.tag);
            } else if (tokens.Length == 2) /* generate */ {
                int result = morpho.generate(tokens[0], tokens[1], Morpho.GUESSER, lemmasForms);
                String guesser = result == Morpho.GUESSER ? "Guesser " : "";
                foreach (TaggedLemmaForms lemmaForms in lemmasForms) {
                    Console.WriteLine("{0}Lemma: {1}", guesser, lemmaForms.lemma);
                    foreach (TaggedForm form in lemmaForms.forms)
                            Console.WriteLine("  {0} {1}", form.form, form.tag);
                }
            }
        }

        return 0;
    }
Beispiel #12
0
    public static int Main(string[] args)
    {
        if (args.Length < 1)
        {
            Console.Error.WriteLine("Usage: RunMorphoCli tagger_file");
            return(1);
        }

        Console.Error.Write("Loading tagger: ");
        Tagger tagger = Tagger.load(args[0]);

        if (tagger == null)
        {
            Console.Error.WriteLine("Cannot load tagger from file '{0}'", args[0]);
            return(1);
        }
        Console.Error.WriteLine("done");

        Forms        forms     = new Forms();
        TaggedLemmas lemmas    = new TaggedLemmas();
        TokenRanges  tokens    = new TokenRanges();
        Tokenizer    tokenizer = tagger.newTokenizer();

        if (tokenizer == null)
        {
            Console.Error.WriteLine("No tokenizer is defined for the supplied model!");
            return(1);
        }

        XmlTextWriter xmlOut = new XmlTextWriter(Console.Out);

        for (bool not_eof = true; not_eof;)
        {
            string        line;
            StringBuilder textBuilder = new StringBuilder();

            // Read block
            while ((not_eof = (line = Console.In.ReadLine()) != null) && line.Length > 0)
            {
                textBuilder.Append(line).Append('\n');
            }
            if (not_eof)
            {
                textBuilder.Append('\n');
            }

            // Tokenize and tag
            string text = textBuilder.ToString();
            tokenizer.setText(text);
            int t = 0;
            while (tokenizer.nextSentence(forms, tokens))
            {
                tagger.tag(forms, lemmas);

                for (int i = 0; i < lemmas.Count; i++)
                {
                    TaggedLemma lemma = lemmas[i];
                    int         token_start = (int)tokens[i].start, token_length = (int)tokens[i].length;
                    xmlOut.WriteString(text.Substring(t, token_start - t));
                    if (i == 0)
                    {
                        xmlOut.WriteStartElement("sentence");
                    }
                    xmlOut.WriteStartElement("token");
                    xmlOut.WriteAttributeString("lemma", lemma.lemma);
                    xmlOut.WriteAttributeString("tag", lemma.tag);
                    xmlOut.WriteString(text.Substring(token_start, token_length));
                    xmlOut.WriteEndElement();
                    if (i + 1 == lemmas.Count)
                    {
                        xmlOut.WriteEndElement();
                    }
                    t = token_start + token_length;
                }
            }
            xmlOut.WriteString(text.Substring(t));
        }
        return(0);
    }
Beispiel #13
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TaggedLemmas obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }