Пример #1
0
        /// <summary>
        /// Gets the spark from graph
        /// </summary>
        /// <returns></returns>
        public termSpark getSpark()
        {
            termSpark spark = new termSpark();

            spark.lemma = lemma;
            var           alls  = this.getAllChildren();
            List <string> added = new List <string>();

            foreach (graphWrapNode <termSparkArm> nd in alls)
            {
                if (nd.item.lexItem != null)
                {
                    if (!(nd.item.lexItem is IConcept))
                    {
                        if (!added.Contains(nd.item.lexItem.Id))
                        {
                            spark.Add(nd.item);
                            added.Add(nd.item.lexItem.Id);
                        }
                    }
                }
            }
            // spark.weight = spark.GetCWeight();
            return(spark);
        }
Пример #2
0
        public bool isMatch(IWeightTableTerm other)
        {
            if (other is termSparkArm)
            {
                termSparkArm other_termSparkArm = (termSparkArm)other;
                if (other_termSparkArm.name.ToLower() == name.ToLower())
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }


            if (other is termSpark)
            {
                termSpark other_termSpark = (termSpark)other;
                if (other_termSpark.isMatch(this))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }


            if (other is weightTableGenericTerm)
            {
                weightTableGenericTerm other_weightTableGenericTerm = (weightTableGenericTerm)other;
                if (other_weightTableGenericTerm.name.ToLower() == name.ToLower())
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            return(other.name.ToLower() == name.ToLower());
        }
Пример #3
0
        public static termSpark getExpandedSpark(this string token, int expansion = 1, ILogBuilder loger = null, bool debug = true, semanticLexiconManager manager = null)
        {
            if (manager == null)
            {
                manager = semanticLexiconManager.manager;
            }
            termSpark spark = null;

            if (expansion == 0)
            {
                spark        = new termSpark(token);
                spark.weight = 1;
                return(spark);
            }

            termGraph tg     = new termGraph(token);
            string    prefix = "lex";

            tg.expand(expansion);

            //if (debug)
            //{
            //    String tree = tg.ToStringTreeview();
            //    tree.saveStringToFile(manager.constructor.projectFolderStructure["logs"].pathFor("exp_" + expansion + "_" + token + ".txt"));
            //}


            spark = tg.getSpark();

            if (debug)
            {
                DataTable dt = spark.GetDataTable("exp_" + expansion + "_" + token, null, true);
                dt.serializeDataTable(dataTableExportEnum.csv, "", manager.constructor.projectFolderStructure["logs"]);
            }


            //if (tokens.Remove(spark.lemma);
            spark.weight = 1;



            return(spark);
        }
Пример #4
0
 public bool Equals(termSpark other)
 {
     return(nominalForm == other.nominalForm);
 }
Пример #5
0
        /// <summary>
        /// Transforms series of tokens into wparks
        /// </summary>
        /// <param name="tokens">The tokens.</param>
        /// <param name="expansion">The expansion.</param>
        /// <param name="loger">The loger.</param>
        /// <returns></returns>
        public static List <termSpark> getSparks(this List <string> tokens, int expansion = 1, ILogBuilder loger = null, bool debug = true)
        {
            List <string>    output = new List <string>();
            List <termSpark> sparks = new List <termSpark>();

            if (!tokens.Any())
            {
                return(sparks);
            }
            StringBuilder sb = new StringBuilder();
            string        qt = "start";
            int           tc = tokens.Count();
            int           i  = 0;
            int           ci = 0;
            int           cl = tc / 10;

            while (!qt.isNullOrEmpty())
            {
                i++;
                ci++;
                if (tokens.Any())
                {
                    qt = tokens.First();
                    tokens.Remove(qt);
                }
                else
                {
                    qt = null;
                    break;
                }

                termSpark spark = getExpandedSpark(qt, expansion, loger, debug);

                foreach (var it in spark.terms)
                {
                    if (tokens.Remove(it.Key))
                    {
                        spark.AFreqPoints++;
                        spark.weight = spark.weight + it.Value.weight;
                    }
                }

                if (loger != null)
                {
                    sb.Append("[" + qt + "] " + tokens.Count().imbGetPercentage(tc, 2));

                    if (ci > cl)
                    {
                        ci = 0;
                        loger.Append(sb.ToString());
                        sb.Clear();
                    }
                }


                if (spark.lemma != null)
                {
                    sparks.Add(spark);
                }
            }
            return(sparks);
        }