FindCoord() 공개 메소드

public FindCoord ( string CoordName ) : int
CoordName string
리턴 int
예제 #1
0
    public TagMatcher(string line, SolarixGrammarEngineNET.GrammarEngine2 gren)
    {
        source = line.Trim();
        id     = ++seq_id;

        string[] toks = source.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
        foreach (string tok in toks)
        {
            if (tok[0] == '\'' && tok[tok.Length - 1] == '\'')
            {
                lexeme = tok.Substring(1, tok.Length - 2);
            }
            else if (tok[0] == '"' && tok[tok.Length - 1] == '"')
            {
                lexeme = tok.Substring(1, tok.Length - 2);
            }
            else
            {
                if (tok.IndexOf(':') == -1)
                {
                    string pos_name = tok.Trim();
                    int    id_class = gren.FindPartOfSpeech(pos_name);
                    if (id_class != -1)
                    {
                        if (pos == null)
                        {
                            pos       = new List <int>();
                            pos_names = new List <string>();
                        }

                        pos.Add(id_class);
                        pos_names.Add(pos_name);
                    }
                    else
                    {
                        int state = 1;

                        string t = tok.Trim();

                        if (t.StartsWith("~"))
                        {
                            t     = t.Substring(1);
                            state = 0;
                        }

                        int id_coord = gren.FindCoord(t);
                        if (id_coord == -1)
                        {
                            throw new ApplicationException(string.Format("Can not find coord [{0}]", tok));
                        }

                        if (gren.CountCoordStates(id_coord) != 0)
                        {
                            throw new ApplicationException(string.Format("[{0}] is not bistable", tok));
                        }

                        if (pairs == null)
                        {
                            pairs = new List <SolarixGrammarEngineNET.CoordPair>();
                        }

                        SolarixGrammarEngineNET.CoordPair p;
                        p.CoordID = id_coord;
                        p.StateID = state;
                        pairs.Add(p);
                    }
                }
                else
                {
                    string[] t3         = tok.Split(':');
                    string   coord_name = t3[0].Trim();
                    string   state_name = t3[1].Trim();

                    int id_class = gren.FindPartOfSpeech(coord_name);
                    if (id_class != -1)
                    {
                        id_lemma    = new List <int>();
                        entry_names = new List <string>();
                        pos_names   = new List <string>();
                        pos_names.Add(coord_name);

                        int    ip    = state_name.IndexOf('{');
                        string ename = state_name.Substring(0, ip);
                        int    ekey  = gren.FindEntry(ename, id_class);

                        if (ekey == -1)
                        {
                            throw new ApplicationException(string.Format("Can not find word entry {0}:{1}", coord_name, ename));
                        }

                        id_lemma.Add(ekey);
                        entry_names.Add(ename);

                        if (entry_pos == null)
                        {
                            entry_pos = new List <int>();
                        }

                        if (!entry_pos.Contains(id_class))
                        {
                            entry_pos.Add(id_class);
                        }
                    }
                    else
                    {
                        int id_coord = gren.FindCoord(coord_name);
                        if (id_coord == -1)
                        {
                            throw new ApplicationException(string.Format("Can not find coord [{0}]", coord_name));
                        }

                        int id_state = -1;
                        if (gren.CountCoordStates(id_coord) == 0)
                        {
                            id_state = int.Parse(state_name);
                            if (id_state < 0 || id_state > 1)
                            {
                                throw new ApplicationException(string.Format("Invalid state name {0} for bistable coord {1}", state_name, coord_name));
                            }
                        }
                        else
                        {
                            id_state = gren.FindState(id_coord, state_name);
                            if (id_state == -1)
                            {
                                throw new ApplicationException(string.Format("Can not find state [{0}:{1}]", coord_name, state_name));
                            }
                        }

                        if (pairs == null)
                        {
                            pairs = new List <SolarixGrammarEngineNET.CoordPair>();
                        }

                        SolarixGrammarEngineNET.CoordPair p;
                        p.CoordID = id_coord;
                        p.StateID = id_state;
                        pairs.Add(p);
                    }
                }
            }
        }
    }