Beispiel #1
0
        private bool VisitTree(Sent sent, int rootid, ref int counter)
        {
            // id start from 1
            // i start from 0
            // that is sent[i].id = i+1
            var rootidx = rootid - 1;

            for (var i = 0; i < rootidx; ++i)
            {
                if (sent[i].Pid == rootid && VisitTree(sent, sent[i].Id, ref counter) == false)
                {
                    return(false);
                }
            }
            counter = counter + 1;
            if (rootid != counter)
            {
                return(false);
            }
            for (var i = rootidx + 1; i < sent.Count; ++i)
            {
                if (sent[i].Pid == rootid && VisitTree(sent, sent[i].Id, ref counter) == false)
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #2
0
        public static Result Evaluate(Sent sent)
        {
            var puncs              = GetPunctuationTags();
            var correctHeads       = 0;
            var correctHeadsNoPunc = 0;
            var sumArcs            = 0;
            var sumArcsNoPunc      = 0;
            var correctArcsNoPunc  = 0;
            var correctArcs        = 0;

            foreach (var ent in sent)
            {
                if (ent.PredParId == ent.Pid)
                {
                    ++correctHeads;
                    if (ent.PredRelation == ent.Relation)
                    {
                        ++correctArcs;
                    }
                }
                ++sumArcs;

                var tag = ent.Pos;
                if (!puncs.Contains(tag) && ent.Pos != "PUNCT" && ent.Pos != "PU")
                {
                    ++sumArcsNoPunc;
                    if (ent.PredParId == ent.Pid)
                    {
                        ++correctHeadsNoPunc;
                        if (ent.PredRelation == ent.Relation)
                        {
                            ++correctArcsNoPunc;
                        }
                    }
                }
            }

            var correctTree       = correctHeads == sent.Count ? 1 : 0;
            var correctTreeNoPunc = correctHeadsNoPunc == sumArcsNoPunc ? 1 : 0;
            var correctRoot       = sent.GetPRoot() == sent.GetRoot() ? 1 : 0;

            return(new Result
            {
                Uas = (float)correctHeads / sumArcs,
                UasNoPunc = (float)correctHeadsNoPunc / sumArcsNoPunc,
                Las = (float)correctArcs / sumArcs,
                LasNoPunc = (float)correctArcsNoPunc / sumArcsNoPunc,
                Uem = correctTree,
                UemNoPunc = correctTreeNoPunc,
                Root = correctRoot
            });
        }
Beispiel #3
0
        private IEnumerable <Sent> LoadFile(string inFile, bool useCpos)
        {
            using (var reader = new StreamReader(inFile, Encoding.UTF8))
            {
                var sent = new Sent();
                var line = reader.ReadLine();
                while (line != null)
                {
                    if (line.StartsWith("#"))
                    {
                        line = reader.ReadLine();
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        yield return(sent);

                        sent = new Sent();
                    }
                    else
                    {
                        // line is ID Form Lemma CPOS POS Feature PID Relation _ _
                        var splits = line.Split();
                        var single = int.TryParse(splits[0], out _);
                        if (single)
                        {
                            sent.Add(new Entry(int.Parse(splits[0]), splits[1], useCpos?splits[3]:splits[4], int.Parse(splits[6]), splits[7]));
                        }
                    }
                    line = reader.ReadLine();
                }
                if (sent.Count != 0)
                {
                    yield return(sent);
                }
            }
        }