public Searcher(Action <string> executeSimilarQuery, bool searchSynonyms, bool searchClasses) { _executeSimilarQuery = executeSimilarQuery; _searchSynonyms = searchSynonyms; _searchClasses = searchClasses; WorkMemory = new WorkMemory(); }
public UnnamedSearcher(string input, Action <string> executeSimilarQuery, WorkMemory workMemory, bool searchClasses, IEnumerable <Node> unnamedNodesInQuery) { _input = input; _executeSimilarQuery = executeSimilarQuery; _workMemory = workMemory; _searchClasses = searchClasses; var dictionary = new Dictionary <string, Node>(); foreach (Node node in unnamedNodesInQuery) { if (!dictionary.ContainsKey(SemanticWeb.Web().GetNameForUnnamedNode(node, false))) { dictionary.Add(SemanticWeb.Web().GetNameForUnnamedNode(node, false), node); } } _query = dictionary; }
public Searcher(string input, Action <string> executeSimilarQuery, bool searchSynonyms, bool searchClasses) { WorkMemory = new WorkMemory(); _executeSimilarQuery = executeSimilarQuery; _searchSynonyms = searchSynonyms; _searchClasses = searchClasses; _input = input; var cw = new ConceptWorker(SemanticWeb.Web().Nodes.Max(x => x.Name.Length), _searchSynonyms); cw.FindAll(_input, null); _inputParts = cw.Concepts.Where(x => x.IsRecognized).Select(x => x.Name).ToList(); _nodesInQuery = GetNodesFromQuery(); WorkMemory.WorkedNodes.AddRange(_nodesInQuery); _unnamedNodesInQuery = GetUnnamedNodesFromQuery(); foreach (var unnamedNodesList in _unnamedNodesInQuery) { WorkMemory.WorkedNodes.AddRange(unnamedNodesList); } for (int i = 0; i < _nodesInQuery.Count; i++) { var node = _nodesInQuery[i]; var i1 = i; var uNodeList = _unnamedNodesInQuery.Where(x => x.Count > i1).Select(x => x[i1]); foreach (var uNode in uNodeList) { Node node1 = uNode; WorkMemory.WorkedArcs.AddRange(SemanticWeb.Web().Arcs.Where(x => x.From == node1.ID && x.Name == "#Name" && x.To == node.ID)); } } _unnamedSearcher = new List <UnnamedSearcher>(); foreach (var unnanedNodesList in _unnamedNodesInQuery) { _unnamedSearcher.Add(new UnnamedSearcher(_input, _executeSimilarQuery, WorkMemory, _searchClasses, unnanedNodesList)); } }
/// <summary> /// Поиск одного слова /// </summary> /// <param name="unnamedNodeToSearch">Неименованная вершина, соответствующая слову из запроса</param> /// <param name="executeSimilarQuery"></param> /// <returns></returns> public static WordResult SearchOneWord(Node unnamedNodeToSearch, Action <string> executeSimilarQuery, WorkMemory workMemory) { var word = SemanticWeb.Web().GetNameForUnnamedNode(unnamedNodeToSearch, false); Node namedNodeToSearch = SemanticWeb.Web().FindNode(word); //определяем имя дуги, которой самый старший предок связан с #System workMemory.WorkedNodes.Add(namedNodeToSearch); workMemory.WorkedNodes.AddRange(SemanticWeb.Web().WayToSystemNodes); //Для метазнаний выполняем поиск по метазнаниям if (SemanticWeb.Web().OldestParentArc(unnamedNodeToSearch.ID) == "#MetaObjects") { return(MetadataSearch.SearchMetaData(unnamedNodeToSearch, word, executeSimilarQuery)); } //Если самая верхняя дуга имеет имя из метаобъектов, ищем слово из предметной области if ( SemanticWeb.Web() .GetAllMetaObjectNames() .Contains(SemanticWeb.Web().OldestParentArc(unnamedNodeToSearch.ID))) { return(ObjectSearcher.SearchObjectData(unnamedNodeToSearch, word, SemanticWeb.Web().OldestParentArc(unnamedNodeToSearch.ID), executeSimilarQuery)); } //throw new ArgumentException(SemanticWeb.ErrMsg + " Слово " + word + " не нашлось"); return(null); }