Ejemplo n.º 1
0
        private bool IsMainObjWithAttrs()
        {
            if (_query.Count == 1)
            {
                return(false);
            }
            List <string> mainObjs = SemanticWeb.Web().GetMainMetaObjectNames(); //список всех mainObj системы
            bool          queryContainsMainObject = _query.Keys.Count(mainObjs.Contains) == 1;

            //правда ли, что в запросе есть 1 mainObj?
            if (!queryContainsMainObject)
            {
                return(false);                                   //если нет, то печаль
            }
            string name = _query.Keys.Single(mainObjs.Contains); //имя этого mainObj
            IEnumerable <string> mainObjAttrs = MetadataSearch.GetAttrList(SafelyGetNodeByName(name, "#MetaObject"), name);
            //список атрибутов mainObj
            int attrCount = 0;

            for (int i = 0; i < _query.Count; i++)
            {
                Node tmpNode  = _query.ElementAt(i).Value;
                var  objAttrs = mainObjAttrs as IList <string> ?? mainObjAttrs.ToList();
                if (objAttrs.Contains(SemanticWeb.Web().OldestParentArc(tmpNode.ID)))
                {
                    attrCount++;
                }
            }
            //mainObjAttrs.Count(x => _nodesInQuery.Any(t => _wordTypes[t.Name] == x));
            //количество этих атрибутов в запросе
            return(attrCount == _query.Count - 1); //если их больше 0, то успех
        }
Ejemplo n.º 2
0
        private IEnumerable <Node> GetMainObjAttrNamesType1()
        {
            // Коктейль
            List <string> mainObjs = SemanticWeb.Web().GetMainMetaObjectNames();
            // Коктейль
            string name = _query.Keys.Single(mainObjs.Contains);
            // Ингредиент
            Node n = SafelyGetNodeByName(name, null);
            IEnumerable <string> mainObjAttrs = MetadataSearch.GetAttrList(n, name);

            return(_query.Values.Where((t, i) => mainObjAttrs.Contains(SemanticWeb.Web().OldestParentArc(_query.Values.ElementAt(i).ID))).ToList());
        }
Ejemplo n.º 3
0
        private IEnumerable <Node> GetMainObjAttrNamesType2()
        {
            List <string> mainObjs = SemanticWeb.Web().GetMainMetaObjectNames();

            string name = string.Empty;

            for (int i = 0; i < _query.Count && name == string.Empty; i++)
            {
                if (mainObjs.Contains(SemanticWeb.Web().OldestParentArc(_query.ElementAt(i).Value.ID)))
                {
                    name = _query.ElementAt(i).Key;
                }
            }
            string metaName     = SemanticWeb.Web().OldestParentArc(SafelyGetNodeByName(name, null).ID);
            var    mainObjAttrs = MetadataSearch.GetAttrList(SafelyGetNodeByName(metaName, null), metaName);

            return
                (_query.Values.Where(
                     (t, i) =>
                     mainObjAttrs.Contains(SemanticWeb.Web().OldestParentArc(_query.ElementAt(i).Value.ID)) &&
                     SemanticWeb.Web().GetNameForUnnamedNode(t, false) != name).ToList());
        }
Ejemplo n.º 4
0
        private bool IsConcreteMainObjWithAttr()
        {
            List <string> mainObjs     = SemanticWeb.Web().GetMainMetaObjectNames();
            var           mainObjNames = new List <string>();

            foreach (var mainObj in mainObjs)
            {
                mainObjNames.AddRange(SemanticWeb.Web().GetAllAttr(
                                          SemanticWeb.Web().Mota(SemanticWeb.Web().Atom("#System")).ID,
                                          mainObj).Select(x => SemanticWeb.Web().GetNameForUnnamedNode(x, false)).ToList());
            }

            bool queryContainsMainObject = _query.Keys.Count(mainObjNames.Contains) == 1;

            if (!queryContainsMainObject)
            {
                return(false);
            }

            string name         = SemanticWeb.Web().OldestParentArc(SafelyGetNodeByName(_query.Keys.Single(mainObjNames.Contains), null).ID);
            var    mainObjAttrs = MetadataSearch.GetAttrList(SafelyGetNodeByName(name, "#MetaObjects"), name);

            int attrCount = 0;

            foreach (string x in mainObjAttrs)
            {
                for (int i = 0; i < _query.Count; i++)
                {
                    if (SemanticWeb.Web().OldestParentArc(_query.ElementAt(i).Value.ID) == x)
                    {
                        attrCount++;
                        break;
                    }
                }
            }
            return(attrCount >= 2);
        }