예제 #1
0
        public PatternTerm popGraphMember()
        {
            PatternTerm member = (PatternTerm)itsGraphMemberStack[itsGraphMemberStack.Count - 1];

            itsGraphMemberStack.RemoveAt(itsGraphMemberStack.Count - 1);
            return(member);
        }
예제 #2
0
        public Pattern Resolve(ResourceMap map)
        {
            PatternTerm theSubject = MakeTerm(GetSubject(), map);

            if (theSubject == null)
            {
                throw new UnknownGraphMemberException(GetSubject());
            }


            PatternTerm thePredicate = MakeTerm(GetPredicate(), map);

            if (thePredicate == null)
            {
                throw new UnknownGraphMemberException(GetSubject());
            }

            PatternTerm theObject = MakeTerm(GetObject(), map);

            if (theObject == null)
            {
                throw new UnknownGraphMemberException(GetSubject());
            }

            return(new Pattern(theSubject, thePredicate, theObject));
        }
예제 #3
0
 public void Handle(QueryParser parser, QueryTokenizer tokenizer, Query query)
 {
     if (tokenizer.Type == QueryTokenizer.TokenType.StatementTerminator)
     {
         if (CurrentTermGroup.stackCount > 2)
         {
             ReportPattern(query);
             SucceedingPatternTermsAreNotRequired();
         }
     }
     else if (tokenizer.Type == QueryTokenizer.TokenType.ValueDelimiter)
     {
         ReportPatternRetainSubjectAndPredicate(query);
         SucceedingPatternTermsAreNotRequired();
     }
     else if (tokenizer.Type == QueryTokenizer.TokenType.PredicateDelimiter)
     {
         ReportPatternRetainSubject(query);
         SucceedingPatternTermsAreNotRequired();
     }
     else if (tokenizer.Type == QueryTokenizer.TokenType.LiteralLanguage)
     {
         PatternTerm member = CurrentTermGroup.popGraphMember();
         CurrentTermGroup.pushGraphMember(new PlainLiteral(member.GetLabel(), tokenizer.TokenText));
     }
     else if (tokenizer.Type == QueryTokenizer.TokenType.LiteralDatatype)
     {
         PatternTerm member = CurrentTermGroup.popGraphMember();
         CurrentTermGroup.pushGraphMember(new TypedLiteral(member.GetLabel(), tokenizer.TokenText));
     }
     else if (tokenizer.Type == QueryTokenizer.TokenType.KeywordFilter)
     {
         EndTermGroup(query);
         ParseFilter(tokenizer, PatternGroup);
         StartTermGroup( );
     }
     else if (tokenizer.Type == QueryTokenizer.TokenType.BeginGeneratedBlankNode)
     {
         BlankNode node = new BlankNode();
         CurrentTermGroup.pushGraphMember(node);
         StartBlankNodeGroup();
         CurrentTermGroup.pushGraphMember(node);
     }
     else if (tokenizer.Type == QueryTokenizer.TokenType.EndGeneratedBlankNode)
     {
         EndTermGroup(query);
     }
     else
     {
         PatternTerm subjectMember = parser.ParseTokenToMember(query);
         CurrentTermGroup.pushGraphMember(subjectMember);
         SucceedingPatternTermsAreRequired();
     }
 }
예제 #4
0
            public void ReportPatternRetainSubject(Query query)
            {
                PatternTerm valueMember     = CurrentTermGroup.popGraphMember();
                PatternTerm predicateMember = CurrentTermGroup.popGraphMember();
                PatternTerm subjectMember   = CurrentTermGroup.popGraphMember();

                Pattern pattern = new Pattern(subjectMember, predicateMember, valueMember);

                PatternGroup.AddPattern(pattern);

                CurrentTermGroup.pushGraphMember(subjectMember);
            }
예제 #5
0
 public Pattern(PatternTerm theSubject, PatternTerm thePredicate, PatternTerm theObject)
 {
     if (null == theSubject)
     {
         throw new ArgumentNullException("theSubject");
     }
     if (null == thePredicate)
     {
         throw new ArgumentNullException("thePredicate");
     }
     if (null == theObject)
     {
         throw new ArgumentNullException("theObject");
     }
     itsSubject   = theSubject;
     itsPredicate = thePredicate;
     itsObject    = theObject;
 }
예제 #6
0
            public void ReportPattern(Query query)
            {
                if (Explain)
                {
                    Console.WriteLine("Reporting a new pattern");
                }
                PatternTerm valueMember     = CurrentTermGroup.popGraphMember();
                PatternTerm predicateMember = CurrentTermGroup.popGraphMember();
                PatternTerm subjectMember   = CurrentTermGroup.popGraphMember();

                Pattern pattern = new Pattern(subjectMember, predicateMember, valueMember);

                if (Explain)
                {
                    Console.WriteLine("Pattern is " + pattern);
                }
                PatternGroup.AddPattern(pattern);
            }
예제 #7
0
 public PatternTerm MakeTerm(PatternTerm member, ResourceMap map)
 {
     if (member is Variable)
     {
         //~ itsVariables[ ((Variable)member).Name ] = member;
         return((Variable)member);
     }
     else
     {
         if (map.HasResourceDenotedBy((GraphMember)member))
         {
             return(map.GetResourceDenotedBy((GraphMember)member));
         }
         else
         {
             return(null);
         }
     }
 }
예제 #8
0
        public Pattern Substitute(Bindings bindings)
        {
            PatternTerm substituteSubject   = itsSubject;
            PatternTerm substitutePredicate = itsPredicate;
            PatternTerm substituteObject    = itsObject;

            if (bindings.Contains(itsSubject))
            {
                substituteSubject = (PatternTerm)bindings.Get(itsSubject);
            }

            if (bindings.Contains(itsPredicate))
            {
                substitutePredicate = (PatternTerm)bindings.Get(itsPredicate);
            }
            if (bindings.Contains(itsObject))
            {
                substituteObject = (PatternTerm)bindings.Get(itsObject);
            }
            return(new Pattern(substituteSubject, substitutePredicate, substituteObject));
        }
예제 #9
0
        private bool ProcessPatternTerm(PatternTerm term, string tableName, string columnName, ArrayList constraints, Hashtable localVariableMentions)
        {
            bool referencesExternalVariables = false;

            if (term is Variable)
            {
                Variable variable = (Variable)term;
                if (itsVariableFirstMentions.Contains(variable.Name))
                {
                    if (localVariableMentions.Contains(variable.Name))
                    {
                        constraints.Add(tableName + "." + columnName + "=" + localVariableMentions[variable.Name]);
                    }
                    else
                    {
                        referencesExternalVariables = true;
                        constraints.Add(tableName + "." + columnName + "=" + itsVariableFirstMentions[variable.Name]);
                        localVariableMentions[variable.Name] = tableName + "." + columnName;
                    }
                }
                else
                {
                    itsVariableFirstMentions[variable.Name] = tableName + "." + columnName;
                    localVariableMentions[variable.Name]    = tableName + "." + columnName;
                    itsVariableTables[variable.Name]        = tableName;
                }

                if (columnName.Equals("subjectHash") || columnName.Equals("predicateHash"))
                {
                    itsNonLiteralVariables[variable.Name] = variable;
                }
            }
            else
            {
                constraints.Add(tableName + "." + columnName + "=" + itsResourcesIndexedByNode[term].GetHashCode());
            }

            return(referencesExternalVariables);
        }
예제 #10
0
 public void AddDescribeTerm(PatternTerm term)
 {
     itsDescribeTerms.Add(term);
     itsSelectAll = false;
 }
예제 #11
0
 public void pushGraphMember(PatternTerm member)
 {
     itsGraphMemberStack.Add(member);
 }