Beispiel #1
0
        private void Normalize_Centroids(WeightBasedPartitioner wbp)
        {
            double minimum = double.MaxValue;

            for (int i = 0; i < wbp.KCentroids[wbp.optimalK].Count; i++)
            {
                if (wbp.KCentroids[wbp.optimalK][i] < minimum)
                {
                    minimum = wbp.KCentroids[wbp.optimalK][i];
                }
            }

            double maximum = 0;

            for (int i = 0; i < wbp.KCentroids[wbp.optimalK].Count; i++)
            {
                wbp.KCentroids[wbp.optimalK][i] -= minimum;
                if (wbp.KCentroids[wbp.optimalK][i] > maximum)
                {
                    maximum = wbp.KCentroids[wbp.optimalK][i];
                }
            }

            if (maximum != 0)
            {
                for (int i = 0; i < wbp.KCentroids[wbp.optimalK].Count; i++)
                {
                    wbp.KCentroids[wbp.optimalK][i] = wbp.KCentroids[wbp.optimalK][i] / maximum;
                }
            }
        }
Beispiel #2
0
        private int getMaximumCentroidIndex(WeightBasedPartitioner wbp)
        {
            double Maximum = 0;
            int    index   = -1;

            for (int i = 0; i < wbp.KCentroids[wbp.optimalK].Count; i++)
            {
                if (wbp.KCentroids[wbp.optimalK][i] >= Maximum)
                {
                    Maximum = wbp.KCentroids[wbp.optimalK][i];
                    index   = i;
                }
            }
            return(index);
        }
Beispiel #3
0
        private List <int> getMaximumCentroidCluster(WeightBasedPartitioner wbp)
        {
            double Maximum = 0;
            int    index   = -1;

            for (int i = 0; i < wbp.KCentroids[wbp.optimalK].Count; i++)
            {
                if (wbp.KCentroids[wbp.optimalK][i] >= Maximum)
                {
                    Maximum = wbp.KCentroids[wbp.optimalK][i];
                    index   = i;
                }
            }

            return(wbp.KGroups[wbp.optimalK][index]);
        }
Beispiel #4
0
        public MindMapTMR Run()
        {
            MainNounFrames_VerbFrames = new Dictionary <NounFrame, Dictionary <MindMapConcept, List <Frame> > >();
            VerbFrames_NounFrames     = new Dictionary <Frame, List <Dictionary <MindMapConcept, List <Frame> > > >();
            NewFrame_OriginalFrame    = new Dictionary <Frame, Frame>();

            //new TMR..
            MindMapTMR NewTMR = new MindMapTMR();

            //Initializing el status beta3 kol frame..
            this.FramesStatus = new List <FrameStatus>();
            for (int i = 0; i < this.TMR.Nounframes.Count + this.TMR.VerbFrames.Count; i++)
            {
                this.FramesStatus.Add(FrameStatus.Hidden);
            }

            //Weight-based partitioning of the nounframes..
            List <Frame> Nounframes = new List <Frame>();

            foreach (Frame f in this.TMR.Nounframes)
            {
                Nounframes.Add(f);
            }
            WeightBasedPartitioner wbp1     = new WeightBasedPartitioner(Nounframes, this.NounFramesWeights);
            List <List <Frame> >   Clusters = wbp1.Partition();

            //getting maximum centroid  cluster
            List <int> dummy = getMaximumCentroidCluster(wbp1);

            this.MainNounFrames = new List <NounFrame>();

            foreach (int i in dummy)
            {
                this.MainNounFrames.Add((NounFrame)wbp1.Frames[i]);
                NewTMR.Nounframes.Add((NounFrame)wbp1.Frames[i]);
                this.NewFrame_OriginalFrame.Add((NounFrame)wbp1.Frames[i], wbp1.Frames[i]);
                this.FramesStatus[this.TMR.Nounframes.IndexOf((NounFrame)wbp1.Frames[i])] = FrameStatus.Present;
            }

            foreach (NounFrame main_nf1 in this.MainNounFrames)
            {
                foreach (NounFrame main_nf2 in this.MainNounFrames)
                {
                    if (main_nf1 != main_nf2)
                    {
                        List <List <Frame> >    paths     = new List <List <Frame> >();
                        List <List <CaseRole> > relations = new List <List <CaseRole> >();
                        GetRelations((Frame)main_nf1, (Frame)main_nf2, out paths, out relations);

                        foreach (List <Frame> path in paths)
                        {
                            foreach (Frame f in path)
                            {
                                if (f is NounFrame)
                                {
                                    if (this.FramesStatus[this.TMR.Nounframes.IndexOf((NounFrame)f)] == FrameStatus.Hidden)
                                    {
                                        NewTMR.Nounframes.Add((NounFrame)f);
                                        this.FramesStatus[this.TMR.Nounframes.IndexOf((NounFrame)f)] = FrameStatus.Present;
                                    }
                                }
                                else
                                {
                                    if (this.FramesStatus[this.TMR.Nounframes.Count + this.TMR.VerbFrames.IndexOf((VerbFrame)f)] == FrameStatus.Hidden)
                                    {
                                        NewTMR.VerbFrames.Add((VerbFrame)f);
                                        this.FramesStatus[this.TMR.Nounframes.Count + this.TMR.VerbFrames.IndexOf((VerbFrame)f)] = FrameStatus.Present;
                                    }
                                }
                            }
                        }
                    }
                }
            }


            for (int i = 0; i < this.MainNounFrames.Count; i++)
            {
                List <VerbFrame> nf_verbframes         = new List <VerbFrame>();
                List <double>    nf_verbframes_weights = new List <double>();

                Dictionary <CaseRole, List <VerbFrame> > AssociatedActions = this.TMR.GetNounFrameAssociatedactions(this.TMR.Nounframes.IndexOf(this.MainNounFrames[i]));
                foreach (CaseRole cr in AssociatedActions.Keys)
                {
                    foreach (VerbFrame vf in AssociatedActions[cr])
                    {
                        if (FramesStatus[this.TMR.VerbFrames.IndexOf(vf) + this.TMR.Nounframes.Count] == FrameStatus.Hidden && nf_verbframes.Contains(vf) == false)
                        {
                            nf_verbframes.Add(vf);
                            nf_verbframes_weights.Add(this.VerbFramesWeights[this.TMR.VerbFrames.IndexOf(vf)]);
                        }
                    }
                }

                List <Frame> Verbframes = new List <Frame>();
                foreach (Frame f in nf_verbframes)
                {
                    Verbframes.Add(f);
                }

                Dictionary <MindMapConcept, List <Frame> > concept_VerbFrames = new Dictionary <MindMapConcept, List <Frame> >();
                Dictionary <MindMapConcept, List <Frame> > concept_NounFrames = new Dictionary <MindMapConcept, List <Frame> >();

                concept_VerbFrames = groupFrames(Verbframes);
                this.MainNounFrames_VerbFrames.Add(this.MainNounFrames[i], concept_VerbFrames);

                foreach (MindMapConcept c in concept_VerbFrames.Keys)
                {
                    if (concept_VerbFrames[c].Count > 1)
                    {
                        List <NounFrame> nounframe = new List <NounFrame>();
                        nounframe.Add(this.MainNounFrames[i]);
                        NewTMR.VerbFrames.Add(new VerbFrame(c.Text, c));
                        NewTMR.VerbFrames[NewTMR.VerbFrames.Count - 1].CaseRoles.Add(CaseRole.Agent, nounframe);
                    }
                    else
                    {
                        VerbFrame original_verbframe = (VerbFrame)concept_VerbFrames[c][0];
                        VerbFrame verbFrame          = cloneVerbFrame(original_verbframe);

                        int index = this.TMR.VerbFrames.IndexOf(original_verbframe);
                        foreach (CaseRole cr in verbFrame.CaseRoles.Keys)
                        {
                            List <Frame> NounFrames = new List <Frame>();
                            foreach (NounFrame nf in verbFrame.CaseRoles[cr])
                            {
                                if (this.MainNounFrames.Contains(nf) == false)
                                {
                                    NounFrames.Add(nf);
                                }
                            }
                            if (NounFrames.Count > 5)
                            {
                                concept_NounFrames = groupFrames(NounFrames);
                                if (this.VerbFrames_NounFrames.ContainsKey(concept_VerbFrames[c][0]) == false)
                                {
                                    List <Dictionary <MindMapConcept, List <Frame> > > list = new List <Dictionary <MindMapConcept, List <Frame> > >();
                                    list.Add(concept_NounFrames);
                                    this.VerbFrames_NounFrames.Add(concept_VerbFrames[c][0], list);
                                }
                                else
                                {
                                    this.VerbFrames_NounFrames[concept_VerbFrames[c][0]].Add(concept_NounFrames);
                                }

                                this.FramesStatus[this.TMR.VerbFrames.IndexOf(verbFrame) + this.TMR.Nounframes.Count] = FrameStatus.Present;

                                foreach (MindMapConcept c_nfs in concept_NounFrames.Keys)
                                {
                                    if (concept_NounFrames[c_nfs].Count > 1)
                                    {
                                        NounFrame newNounFrame = new NounFrame(c_nfs.Text, c_nfs);
                                        NewTMR.Nounframes.Add(newNounFrame);
                                        verbFrame.CaseRoles[cr].Add(newNounFrame);

                                        foreach (Frame frame in concept_NounFrames[c_nfs])
                                        {
                                            this.FramesStatus[this.TMR.Nounframes.IndexOf((NounFrame)frame)] = FrameStatus.Grouped;
                                            verbFrame.CaseRoles[cr].Remove((NounFrame)frame);
                                        }
                                    }

                                    else
                                    {
                                        this.FramesStatus[this.TMR.Nounframes.IndexOf((NounFrame)concept_NounFrames[c_nfs][0])] = FrameStatus.Present;
                                    }
                                }
                            }
                        }
                        NewTMR.VerbFrames.Add(verbFrame);
                        NewFrame_OriginalFrame.Add(verbFrame, this.TMR.VerbFrames[index]);
                    }
                }
            }

            for (int k = 0; k < NewTMR.VerbFrames.Count; k++)
            {
                VerbFrame vf = NewTMR.VerbFrames[k];
                foreach (TemporalRelationType trt in vf.TemporalRelations.Keys)
                {
                    for (int i = 0; i < vf.TemporalRelations[trt].Count; i++)
                    {
                        if (NewTMR.VerbFrames.Contains(vf.TemporalRelations[trt][i]) == false)
                        {
                            NewTMR.VerbFrames.Add(vf.TemporalRelations[trt][i]);
                        }
                    }
                }
            }

            for (int k = 0; k < NewTMR.VerbFrames.Count; k++)
            {
                VerbFrame vf = NewTMR.VerbFrames[k];
                foreach (DomainRelationType drt in vf.DomainRelations.Keys)
                {
                    for (int i = 0; i < vf.DomainRelations[drt].Count; i++)
                    {
                        if (NewTMR.VerbFrames.Contains(vf.DomainRelations[drt][i]) == false)
                        {
                            NewTMR.VerbFrames.Add(vf.DomainRelations[drt][i]);
                        }
                    }
                }
            }

            foreach (VerbFrame vf in NewTMR.VerbFrames)
            {
                foreach (CaseRole cr in vf.CaseRoles.Keys)
                {
                    for (int i = 0; i < vf.CaseRoles[cr].Count; i++)
                    {
                        if (NewTMR.Nounframes.Contains(vf.CaseRoles[cr][i]) == false)
                        {
                            NewTMR.Nounframes.Add(vf.CaseRoles[cr][i]);
                        }
                    }
                }
            }

            foreach (VerbFrame vf in NewTMR.VerbFrames)
            {
                foreach (DomainRelationType drt in vf.DomainRelations_n.Keys)
                {
                    for (int i = 0; i < vf.DomainRelations_n[drt].Count; i++)
                    {
                        if (NewTMR.Nounframes.Contains(vf.DomainRelations_n[drt][i]) == false)
                        {
                            NewTMR.Nounframes.Add(vf.DomainRelations_n[drt][i]);
                        }
                    }
                }
            }

            foreach (VerbFrame vf in NewTMR.VerbFrames)
            {
                foreach (TemporalRelationType trt in vf.TemporalRelations_n.Keys)
                {
                    for (int i = 0; i < vf.TemporalRelations_n[trt].Count; i++)
                    {
                        if (NewTMR.Nounframes.Contains(vf.TemporalRelations_n[trt][i]) == false)
                        {
                            NewTMR.Nounframes.Add(vf.TemporalRelations_n[trt][i]);
                        }
                    }
                }
            }

            List <NounFrame> dummylist = new List <NounFrame>();

            foreach (NounFrame nf in NewTMR.Nounframes)
            {
                foreach (CaseRole cr in nf.Ownerof.Keys)
                {
                    for (int i = 0; i < nf.Ownerof[cr].Count; i++)
                    {
                        if (TMR.Nounframes.Contains(nf.Ownerof[cr][i]) == true && NewTMR.Nounframes.Contains(nf.Ownerof[cr][i]) == false && this.FramesStatus[this.TMR.Nounframes.IndexOf(nf.Ownerof[cr][i])] != FrameStatus.Grouped)
                        {
                            dummylist.Add(nf.Ownerof[cr][i]);
                        }
                    }
                }
            }

            foreach (NounFrame nf in TMR.Nounframes)
            {
                foreach (CaseRole cr in nf.Ownerof.Keys)
                {
                    foreach (NounFrame nf2 in nf.Ownerof[cr])
                    {
                        if (NewTMR.Nounframes.Contains(nf2) == true && NewTMR.Nounframes.Contains(nf) == false)
                        {
                            NewTMR.Nounframes.Add(nf);
                        }
                    }
                }
            }



            foreach (NounFrame nf in dummylist)
            {
                if (NewTMR.Nounframes.Contains(nf) == false)
                {
                    NewTMR.Nounframes.Add(nf);
                }
            }



            return(NewTMR);
        }