예제 #1
0
        private void FilterToSinglePredicate(SimpleFBObject node, string predicate)
        {
            PredicateAndObjects predicateAndObject = null;

            foreach (PredicateAndObjects p in node.Objects)
            {
                if (p.Predicate == predicate)
                {
                    predicateAndObject = p;
                    break;
                }
            }
            if (predicateAndObject == null)
            {
                // Didn't find the predicate
                node.Objects = new PredicateAndObjects[0];
            }
            node.Objects = new PredicateAndObjects[1] {
                predicateAndObject
            };
        }
예제 #2
0
        public SimpleFBObject GetSimpleObjectFilteredPredicateAndObjects(string subjectMid, string predicate)
        {
            try
            {
                logger.Log("GetSimpleObjectFilteredPredicateAndObjects called for subj=" + subjectMid + ", pred=" + predicate);

                Dictionary <string, FBObject> nodesInGraph;
                SimpleFBObject initial = GetSimpleObjectPredicatesAndCVTs(subjectMid, out nodesInGraph, int.MaxValue, true);

                string[] predicateParts = predicate.Split(' ');

                if (predicateParts.Length < 1 || predicateParts.Length > 2)
                {
                    return(null);
                }

                FilterToSinglePredicate(initial, predicateParts[0]);
                if (initial.Objects.Length == 0)
                {
                    return(initial); // Doesn't contain the desired predicate
                }
                PredicateAndObjects predicateAndObjects = initial.Objects[0];

                if (predicateParts.Length == 2)
                {
                    foreach (FBObject fbo in predicateAndObjects.Objects)
                    {
                        if (fbo is CVTFBObject)
                        {
                            foreach (PredicateAndObjects poi in (((CVTFBObject)fbo).Objects))
                            {
                                if (poi.Predicate == predicateParts[1])
                                {
                                    foreach (FBObject fboObj in poi.Objects)
                                    {
                                        if (fboObj is SimpleFBObject)
                                        {
                                            SimpleFBObject fboAnswer = (SimpleFBObject)fboObj;
                                            if (fboAnswer.Objects == null)
                                            {
                                                // We need to expand the objects for this node
                                                PredicateAndObjects[] resultsForObj =
                                                    GetPredicatesAndNamedObjectsIncludingCVTs(nodesInGraph, fboAnswer.Mid,
                                                                                              int.MaxValue, false);
                                                fboAnswer.Objects = resultsForObj;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    foreach (FBObject fbo in predicateAndObjects.Objects)
                    {
                        if (fbo is SimpleFBObject)
                        {
                            SimpleFBObject fboAnswer = (SimpleFBObject)fbo;
                            if (fboAnswer.Objects == null)
                            {
                                // We need to expand the objects for this node
                                PredicateAndObjects[] resultsForObj = GetPredicatesAndNamedObjectsIncludingCVTs(
                                    nodesInGraph, fboAnswer.Mid, int.MaxValue, false);
                                fboAnswer.Objects = resultsForObj;
                            }
                        }
                    }
                }
                return(initial);
            }
            catch (Exception e)
            {
                logger.LogException("GetSimpleObjectFilteredPredicateAndObjects failed", e);
                return(null);
            }
        }