Ejemplo n.º 1
0
        /// <summary>
        /// Gets the web lemma.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="node">The node.</param>
        /// <param name="options">The options.</param>
        /// <returns></returns>
        public static webLemmaTerm GetWebLemma(webLemmaTerm parent, freeGraphNodeBase node, lemmaExpansionOptions options)
        {
            webLemmaTerm term = new webLemmaTerm();

            term.name        = node.name;
            term.nominalForm = node.name;
            term.weight      = node.weight;

            if (options.HasFlag(lemmaExpansionOptions.initialWeightToOne))
            {
                term.weight = 1;
            }

            if (options.HasFlag(lemmaExpansionOptions.initialWeightFromParent))
            {
                term.weight = parent.weight;
            }

            if (options.HasFlag(lemmaExpansionOptions.weightAsSemanticDistanceFromParent))
            {
                Double distanceFactor = node.distance.GetRatio(1);
                term.weight = term.weight * distanceFactor;
            }

            return(term);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generates simple-styled graph
        /// </summary>
        /// <param name="addLegend">if set to <c>true</c> [add legend].</param>
        /// <returns></returns>
        public DirectedGraph GetSimpleGraph(Boolean addLegend = true)
        {
            DirectedGraph output = new DirectedGraph();

            output.Title  = name;
            output.Layout = imbSCI.Graph.DGML.enums.GraphLayoutEnum.Sugiyama;
            output.NeighborhoodDistance = 20;

            var res  = output.Categories.AddOrGetCategory(0, "Reserve Term", "");
            var sec  = output.Categories.AddOrGetCategory(1, "Secondary Term", "");
            var prim = output.Categories.AddOrGetCategory(2, "Primary Term", "");

            res.Stroke           = Color.LightGray.toHexColor();
            res.StrokeThinkness  = 2;
            res.Background       = Color.WhiteSmoke.toHexColor();
            res.StrokeDashArray  = "5,2,5,2";
            sec.Stroke           = Color.Gray.toHexColor();
            sec.StrokeThinkness  = 4;
            sec.Background       = Color.WhiteSmoke.toHexColor();
            prim.Stroke          = Color.Black.toHexColor();
            prim.StrokeThinkness = 6;
            prim.Background      = Color.WhiteSmoke.toHexColor();


            foreach (freeGraphNodeBase node in nodes)
            {
                Node nd = output.Nodes.AddNode(node.name, node.name + " " + node.weight.ToString("F4"));
                nd.Category = node.type.ToString();
            }

            foreach (freeGraphLinkBase link in links)
            {
                Link l = new Link(link.nodeNameA, link.nodeNameB);

                freeGraphNodeBase tn = GetNode(link.nodeNameB);


                output.Links.Add(l);
            }

            if (addLegend)
            {
                var legendNode = output.Nodes.AddNode("TermCategory", "LEGEND");
                var resNode    = output.Nodes.AddNode("TCRES", "Reserve Term");
                resNode.Category = res.Id;
                var secNode = output.Nodes.AddNode("TCSEC", "Secondary Term");
                secNode.Category = sec.Id;
                var primNode = output.Nodes.AddNode("TCPRIM", "Primary Term");
                primNode.Category = prim.Id;

                output.Links.AddLink(legendNode, resNode, "Term Category");
                output.Links.AddLink(legendNode, secNode, "Term Category");
                output.Links.AddLink(legendNode, primNode, "Term Category");
            }


            return(output);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts the graph node into <see cref="webLemmaTerm"/> instance
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        public static webLemmaTerm GetWebLemma(freeGraphNodeBase node)
        {
            webLemmaTerm term = new webLemmaTerm();

            term.name        = node.name;
            term.nominalForm = node.name;
            term.weight      = node.weight;
            return(term);
        }
Ejemplo n.º 4
0
        internal void AddOrUpdateNode(freeGraphNodeBase node, freeGraphLink link, freeGraphNodeAndLinks links, Boolean typeToMin, lemmaExpansionOptions options)
        {
            if (ContainsNode(node.name, true))
            {
                var nd = GetNode(node.name, true);
                if (options.HasFlag(lemmaExpansionOptions.divideWeightByNumberOfSynonims))
                {
                    nd.weight = nd.weight + (node.weight.GetRatio(links.linkedNodeClones.Count));
                }
                else if (options.HasFlag(lemmaExpansionOptions.weightAsSemanticDistanceThatIsSumOfLinkWeights))
                {
                    nd.weight = nd.weight + node.weight.GetRatio(node.distance);
                    if (nd.distance > 1)
                    {
                        nd.distance = Math.Min(nd.distance, node.distance + link.linkBase.weight);
                    }
                    else
                    {
                        nd.distance = node.distance + link.linkBase.weight;
                    }
                }
                else
                {
                    nd.weight = nd.weight + node.weight;
                }

                if (typeToMin)
                {
                    nd.type = Math.Min(nd.type, node.type);
                }
                else
                {
                    nd.type = Math.Max(nd.type, node.type);
                }
            }
            else
            {
                if (options.HasFlag(lemmaExpansionOptions.divideWeightByNumberOfSynonims))
                {
                    AddNode(node.name, node.weight.GetRatio(links.linkedNodeClones.Count), node.type);
                }
                else if (options.HasFlag(lemmaExpansionOptions.weightAsSemanticDistanceThatIsSumOfLinkWeights))
                {
                    AddNode(node.name, node.weight.GetRatio(node.distance), node.type).distance = node.distance + link.linkBase.weight;
                }
                else
                {
                    AddNode(node.name, node.weight, node.type);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Converts the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="depthLimit">The depth limit.</param>
        /// <returns></returns>
        public override freeGraph Convert(T source, Int32 depthLimit = 500, IEnumerable <T> rootNodes = null)
        {
            freeGraph output = new freeGraph();

            output.DisableCheck = true;
            output.Id           = source.name;
            output.description  = "FreeGraph built from " + source.GetType().Name + ":GraphNodeBase graph";

            var nodes = source.getAllChildren(null, false, false, 1, depthLimit, true);

            Dictionary <T, freeGraphNodeBase> nodeDict = new Dictionary <T, freeGraphNodeBase>();

            foreach (var ch in nodes)
            {
                T   child = (T)ch;
                var node  = output.AddNewNode(GetNodeName(child), GetNodeWeight(child), GetNodeType(child));
                nodeDict.Add(child, node);
            }

            foreach (var ch in nodes)
            {
                if (ch.parent != null)
                {
                    T parent = (T)ch.parent;
                    T child  = (T)ch;
                    if ((parent != null) && (child != null))
                    {
                        freeGraphNodeBase gParent = nodeDict[parent];
                        freeGraphNodeBase gChild  = nodeDict[child];
                        var lnk = output.AddLink(gParent.name, gChild.name, GetLinkWeight(parent, child), GetLinkType(parent, child));
                        lnk.linkLabel = GetLinkLabel(parent, child);
                    }
                }
            }
            output.DisableCheck = false;
            output.RebuildIndex();
            return(output);
        }