Example #1
0
        public OntologyDesc GetOntologyDesc()
        {
            // Keywords
            //var searcher = new MetadataCacheSearcher();
            var list = new List<string>();
            var keywordsList = list;//searcher.GetKeywords();
            keywordsList.Add(Constants.RootName);
            var sortedKeywords = new SortedSet<string>(keywordsList);

            // Ontology tree
            var tree = new OntologyTree();
            var parentNode = new OntologyNode(Constants.RootName);
            foreach (var keyword in keywordsList.Where(keyword => keyword != Constants.RootName))
            {
                parentNode.children.Add(new OntologyNode(keyword));
            }
            tree.Nodes.Add(parentNode);

            // Return result
            var result = new OntologyDesc
            {
                Keywords = sortedKeywords,
                OntoloyTree = tree,
            };
            return result;
        }
Example #2
0
        public OntologyDesc GetOntologyDesc()
        {
            // Keywords
            //var searcher = new MetadataCacheSearcher();
            var list         = new List <string>();
            var keywordsList = list;//searcher.GetKeywords();

            keywordsList.Add(Constants.RootName);
            var sortedKeywords = new SortedSet <string>(keywordsList);

            // Ontology tree
            var tree       = new OntologyTree();
            var parentNode = new OntologyNode(Constants.RootName);

            foreach (var keyword in keywordsList.Where(keyword => keyword != Constants.RootName))
            {
                parentNode.children.Add(new OntologyNode(keyword));
            }
            tree.Nodes.Add(parentNode);

            // Return result
            var result = new OntologyDesc
            {
                Keywords    = sortedKeywords,
                OntoloyTree = tree,
            };

            return(result);
        }
Example #3
0
        public void UpdateKeywordsAndOntology(CatalogSettings catalogSettings = null)
        {
            var desc = KeywordsServicesFactory.GetKeywordsList(catalogSettings ?? _parent.CatalogSettings).GetOntologyDesc();

            // Select root of OntoloyTree
            if (_selectedKeywords == null &&
                desc.OntoloyTree.Nodes.Count > 0)
            {
                _selectedKeywords = new[] { desc.OntoloyTree.Nodes[0].title };
            }

            _ontologyDesc = desc;
            RaiseKeywordsChanged();
        }
Example #4
0
        /// <summary>
        /// Create deep from source into current instance.
        /// </summary>
        /// <param name="source">Source.</param>
        /// <exception cref="ArgumentNullException"><paramref name="source"/>must be not null.</exception>
        public void Copy(KeywordsSettings source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            var selectedKeywords = new List <string>(source.SelectedKeywords.Count());

            selectedKeywords.AddRange(source.SelectedKeywords.Select(s => s));
            SelectedKeywords = selectedKeywords;

            _ontologyDesc = source._ontologyDesc;
            RaiseKeywordsChanged();
        }
Example #5
0
        public void UpdateKeywordsAndOntology(CatalogSettings catalogSettings = null)
        {
            var desc = KeywordsServicesFactory.GetKeywordsList(catalogSettings ?? _parent.CatalogSettings).GetOntologyDesc();

            // Select root of OntoloyTree
            if (_selectedKeywords == null &&
                desc.OntoloyTree.Nodes.Count > 0)
            {
                _selectedKeywords = new[] { desc.OntoloyTree.Nodes[0].title };
            }

            _ontologyDesc = desc;
            RaiseKeywordsChanged();
        }
Example #6
0
        /// <summary>
        /// Create deep from source into current instance.
        /// </summary>
        /// <param name="source">Source.</param>
        /// <exception cref="ArgumentNullException"><paramref name="source"/>must be not null.</exception>
        public void Copy(KeywordsSettings source)
        {
            if (source == null) throw new ArgumentNullException("source");

            var selectedKeywords = new List<string>(source.SelectedKeywords.Count());
            selectedKeywords.AddRange(source.SelectedKeywords.Select(s => s));
            SelectedKeywords = selectedKeywords;

            _ontologyDesc = source._ontologyDesc;
            RaiseKeywordsChanged();
        }
        internal static List<string> RefineKeywordList(OntologyDesc desc, List<string> keywords)
        {
            var ontologyTree = desc.OntoloyTree;
            var allKeywords = desc.Keywords;

            // If searching 1st tier keywords, clear the list.
            var tier1Keywords = ontologyTree.Nodes.Select(d => d.title);
            if (tier1Keywords.Any(keywords.Contains))
            {
                keywords.Clear();
                return keywords;
            }

            // Remove duplicates
            keywords = keywords.Distinct().ToList();

            // Remove invalid keywords
            var toDelete = new HashSet<string>(keywords.Where(k => !allKeywords.Contains(k)));

            // Remove keywords if their ancestors are also in the list.
            foreach (var keyword in keywords)
            {
                if (toDelete.Contains(keyword)) continue;
                var node = ontologyTree.FindNode(keyword);
                if (node == null) continue;

                foreach (var other in keywords)
                {
                    if (other == keyword) continue;
                    if (toDelete.Contains(other)) continue;
                    if (node.HasChild(other))
                    {
                        toDelete.Add(other);
                    }
                }
            }
            foreach (var del in toDelete)
            {
                keywords.Remove(del);
            }

            // Replace 2nd tier keywords with their 3rd tier child keywords.
            // 2nd tier keywords cannot be searched at HIS Central.
            foreach (var tier2Node in ontologyTree.Nodes.SelectMany(node => node.children))
            {
                var tier2keyword = tier2Node.title;
                if (!keywords.Contains(tier2keyword)) continue;

                // Remove 2nd tier keyword
                keywords.Remove(tier2keyword);

                // Add 3rd tier keywords that are children of the removed 2nd tier keyword.
                var tier3Keywords = tier2Node.children.Select(d => d.title);
                foreach (var tier3keyword in tier3Keywords.Where(tier3keyword => !keywords.Contains(tier3keyword)))
                {
                    keywords.Add(tier3keyword);
                }
            }

            return keywords;
        }
        public OntologyDesc GetOntologyDesc()
        {
            // Synonyms and keywords
            var tmpsyndoc = ReadOntologySynonymsXmlFile();
            keywordsList = new SortedSet<string>();
            var synonyms = new List<OntologyPath>();
            var root = tmpsyndoc.DocumentElement;
            foreach (XmlElement elem in root.ChildNodes)
            {
                var ontoPath = new OntologyPath();
                foreach (XmlElement child in elem.ChildNodes)
                {
                    var text = child.InnerText.Trim();
                    if (child.Name == "conceptID")
                    {
                        int conceptID;
                        if (Int32.TryParse(text, out conceptID))
                            ontoPath.ConceptID = conceptID;
                    }
                    else if (child.Name == "ConceptName")
                    {
                        ontoPath.ConceptName = text;
                    }
                    else if (child.Name == "ConceptPath")
                    {
                        ontoPath.ConceptPath = text;
                    }
                    else if (child.Name == "SearchableKeyword")
                    {
                        ontoPath.SearchableKeyword = text;
                    }
                }
                // Add to sysnonyms, only if SearchableKeyword != ConceptName
                if (!string.Equals(ontoPath.SearchableKeyword, ontoPath.ConceptName) &&
                    !string.IsNullOrEmpty(ontoPath.SearchableKeyword))
                {
                    synonyms.Add(ontoPath);
                }
                if (!String.IsNullOrWhiteSpace(ontoPath.SearchableKeyword))
                {
                    keywordsList.Add(ontoPath.SearchableKeyword);
                }
            }

            // Ontology tree
            var tree = new OntologyTree();
            var tmpxmldoc = ReadOntologyXmlFile();
            FillTree(tmpxmldoc.DocumentElement, tree.Nodes);

            // Replace Hydroshpere with All
            keywordsList.Remove("Hydrosphere");
            keywordsList.Add(Constants.RootName);
            if (tree.Nodes.Count > 0)
            {
                tree.Nodes[0].title = Constants.RootName;
            }

            // Return result
            var result = new OntologyDesc
            {
                OntoloyTree = tree,
                Keywords = keywordsList,
                Synonyms = synonyms,
            };
            return result;
        }
        public OntologyDesc GetOntologyDesc()
        {
            // Synonyms and keywords
            var tmpsyndoc = ReadOntologySynonymsXmlFile();

            keywordsList = new SortedSet <string>();
            var synonyms = new List <OntologyPath>();
            var root     = tmpsyndoc.DocumentElement;

            foreach (XmlElement elem in root.ChildNodes)
            {
                var ontoPath = new OntologyPath();
                foreach (XmlElement child in elem.ChildNodes)
                {
                    var text = child.InnerText.Trim();
                    if (child.Name == "conceptID")
                    {
                        int conceptID;
                        if (Int32.TryParse(text, out conceptID))
                        {
                            ontoPath.ConceptID = conceptID;
                        }
                    }
                    else if (child.Name == "ConceptName")
                    {
                        ontoPath.ConceptName = text;
                    }
                    else if (child.Name == "ConceptPath")
                    {
                        ontoPath.ConceptPath = text;
                    }
                    else if (child.Name == "SearchableKeyword")
                    {
                        ontoPath.SearchableKeyword = text;
                    }
                }
                // Add to sysnonyms, only if SearchableKeyword != ConceptName
                if (!string.Equals(ontoPath.SearchableKeyword, ontoPath.ConceptName) &&
                    !string.IsNullOrEmpty(ontoPath.SearchableKeyword))
                {
                    synonyms.Add(ontoPath);
                }
                if (!String.IsNullOrWhiteSpace(ontoPath.SearchableKeyword))
                {
                    keywordsList.Add(ontoPath.SearchableKeyword);
                }
            }

            // Ontology tree
            var tree      = new OntologyTree();
            var tmpxmldoc = ReadOntologyXmlFile();

            FillTree(tmpxmldoc.DocumentElement, tree.Nodes);

            // Replace Hydroshpere with All
            keywordsList.Remove("Hydrosphere");
            keywordsList.Add(Constants.RootName);
            if (tree.Nodes.Count > 0)
            {
                tree.Nodes[0].title = Constants.RootName;
            }

            // Return result
            var result = new OntologyDesc
            {
                OntoloyTree = tree,
                Keywords    = keywordsList,
                Synonyms    = synonyms,
            };

            return(result);
        }
        internal static List <string> RefineKeywordList(OntologyDesc desc, List <string> keywords)
        {
            var ontologyTree = desc.OntoloyTree;
            var allKeywords  = desc.Keywords;

            // If searching 1st tier keywords, clear the list.
            var tier1Keywords = ontologyTree.Nodes.Select(d => d.title);

            if (tier1Keywords.Any(keywords.Contains))
            {
                keywords.Clear();
                return(keywords);
            }

            // Remove duplicates
            keywords = keywords.Distinct().ToList();

            // Remove invalid keywords
            var toDelete = new HashSet <string>(keywords.Where(k => !allKeywords.Contains(k)));

            // Remove keywords if their ancestors are also in the list.
            foreach (var keyword in keywords)
            {
                if (toDelete.Contains(keyword))
                {
                    continue;
                }
                var node = ontologyTree.FindNode(keyword);
                if (node == null)
                {
                    continue;
                }

                foreach (var other in keywords)
                {
                    if (other == keyword)
                    {
                        continue;
                    }
                    if (toDelete.Contains(other))
                    {
                        continue;
                    }
                    if (node.HasChild(other))
                    {
                        toDelete.Add(other);
                    }
                }
            }
            foreach (var del in toDelete)
            {
                keywords.Remove(del);
            }

            // Replace 2nd tier keywords with their 3rd tier child keywords.
            // 2nd tier keywords cannot be searched at HIS Central.
            foreach (var tier2Node in ontologyTree.Nodes.SelectMany(node => node.children))
            {
                var tier2keyword = tier2Node.title;
                if (!keywords.Contains(tier2keyword))
                {
                    continue;
                }

                // Remove 2nd tier keyword
                keywords.Remove(tier2keyword);

                // Add 3rd tier keywords that are children of the removed 2nd tier keyword.
                var tier3Keywords = tier2Node.children.Select(d => d.title);
                foreach (var tier3keyword in tier3Keywords.Where(tier3keyword => !keywords.Contains(tier3keyword)))
                {
                    keywords.Add(tier3keyword);
                }
            }

            return(keywords);
        }