public PatternTerm popGraphMember() { PatternTerm member = (PatternTerm)itsGraphMemberStack[itsGraphMemberStack.Count - 1]; itsGraphMemberStack.RemoveAt(itsGraphMemberStack.Count - 1); return(member); }
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)); }
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(); } }
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); }
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; }
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); }
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); } } }
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)); }
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); }
public void AddDescribeTerm(PatternTerm term) { itsDescribeTerms.Add(term); itsSelectAll = false; }
public void pushGraphMember(PatternTerm member) { itsGraphMemberStack.Add(member); }