本文整理汇总了C#中IToken.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IToken.GetType方法的具体用法?C# IToken.GetType怎么用?C# IToken.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IToken
的用法示例。
在下文中一共展示了IToken.GetType方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Error
/// <summary>
/// Helper method for raising informative standardised Parser Errors
/// </summary>
/// <param name="msg">The Error Message</param>
/// <param name="t">The Token that is the cause of the Error</param>
/// <returns></returns>
public static RdfParseException Error(String msg, IToken t)
{
StringBuilder output = new StringBuilder();
output.Append("[");
output.Append(t.GetType().Name);
output.Append(" at Line ");
output.Append(t.StartLine);
output.Append(" Column ");
output.Append(t.StartPosition);
output.Append(" to Line ");
output.Append(t.EndLine);
output.Append(" Column ");
output.Append(t.EndPosition);
output.Append("] ");
output.Append(msg);
return new RdfParseException(output.ToString(), t);
}
示例2: TryResolveUri
/// <summary>
/// Attempts to resolve a QName or URI Token into a URI Node and produces appropriate error messages if this fails
/// </summary>
/// <param name="context">Parser Context</param>
/// <param name="t">Token to resolve</param>
/// <returns></returns>
public static INode TryResolveUri(IParserContext context, IToken t)
{
switch (t.TokenType)
{
case Token.QNAME:
try
{
return context.Handler.CreateUriNode(new Uri(Tools.ResolveQName(t.Value, context.Namespaces, context.BaseUri)));
}
catch (UriFormatException formatEx)
{
throw new RdfParseException("Unable to resolve the QName '" + t.Value + "' due to the following error:\n" + formatEx.Message, t, formatEx);
}
catch (RdfException rdfEx)
{
throw new RdfParseException("Unable to resolve the QName '" + t.Value + "' due to the following error:\n" + rdfEx.Message, t, rdfEx);
}
case Token.URI:
try
{
String uri = Tools.ResolveUri(t.Value, context.BaseUri.ToSafeString());
return context.Handler.CreateUriNode(new Uri(uri));
}
catch (UriFormatException formatEx)
{
throw new RdfParseException("Unable to resolve the URI '" + t.Value + "' due to the following error:\n" + formatEx.Message, t, formatEx);
}
catch (RdfException rdfEx)
{
throw new RdfParseException("Unable to resolve the URI '" + t.Value + "' due to the following error:\n" + rdfEx.Message, t, rdfEx);
}
default:
throw ParserHelper.Error("Unexpected Token '" + t.GetType().ToString() + "' encountered, expected a URI/QName Token to resolve into a URI", t);
}
}
示例3: TryParseTriple
private void TryParseTriple(IRdfHandler handler, IToken s, IToken p, IToken o, Uri graphUri)
{
INode subj, pred, obj;
switch (s.TokenType)
{
case Token.BLANKNODEWITHID:
subj = handler.CreateBlankNode(s.Value.Substring(2));
break;
case Token.URI:
subj = ParserHelper.TryResolveUri(handler, s);
break;
default:
throw ParserHelper.Error("Unexpected Token '" + s.GetType().ToString() + "' encountered, expected a Blank Node/URI as the Subject of a Triple", s);
}
switch (p.TokenType)
{
case Token.URI:
pred = ParserHelper.TryResolveUri(handler, p);
break;
default:
throw ParserHelper.Error("Unexpected Token '" + p.GetType().ToString() + "' encountered, expected a URI as the Predicate of a Triple", p);
}
switch (o.TokenType)
{
case Token.BLANKNODEWITHID:
obj = handler.CreateBlankNode(o.Value.Substring(2));
break;
case Token.LITERAL:
obj = handler.CreateLiteralNode(o.Value);
break;
case Token.LITERALWITHDT:
String dtUri = ((LiteralWithDataTypeToken)o).DataType;
obj = handler.CreateLiteralNode(o.Value, new Uri(dtUri.Substring(1, dtUri.Length - 2)));
break;
case Token.LITERALWITHLANG:
obj = handler.CreateLiteralNode(o.Value, ((LiteralWithLanguageSpecifierToken)o).Language);
break;
case Token.URI:
obj = ParserHelper.TryResolveUri(handler, o);
break;
default:
throw ParserHelper.Error("Unexpected Token '" + o.GetType().ToString() + "' encountered, expected a Blank Node/Literal/URI as the Object of a Triple", o);
}
if (!handler.HandleTriple(new Triple(subj, pred, obj, graphUri))) throw ParserHelper.Stop();
}
示例4: TryParseLiteral
//.........这里部分代码省略.........
/// <param name="context">Parser Context</param>
/// <param name="lit">Literal Token</param>
/// <returns></returns>
private INode TryParseLiteral(TokenisingParserContext context, IToken lit)
{
IToken next;
String dturi;
switch (lit.TokenType)
{
case Token.LITERAL:
case Token.LONGLITERAL:
next = context.Tokens.Peek();
if (next.TokenType == Token.LANGSPEC)
{
//Has a Language Specifier
next = context.Tokens.Dequeue();
return context.Handler.CreateLiteralNode(lit.Value, next.Value);
}
else if (next.TokenType == Token.DATATYPE)
{
//Has a Datatype
next = context.Tokens.Dequeue();
try
{
if (next.Value.StartsWith("<"))
{
dturi = next.Value.Substring(1, next.Value.Length - 2);
return context.Handler.CreateLiteralNode(lit.Value, new Uri(Tools.ResolveUri(dturi, context.BaseUri.ToSafeString())));
}
else
{
dturi = Tools.ResolveQName(next.Value, context.Namespaces, context.BaseUri);
return context.Handler.CreateLiteralNode(lit.Value, new Uri(dturi));
}
}
catch (RdfException rdfEx)
{
throw new RdfParseException("Unable to resolve the Datatype '" + next.Value + "' due to the following error:\n" + rdfEx.Message, next, rdfEx);
}
}
else
{
//Just an untyped Literal
return context.Handler.CreateLiteralNode(lit.Value);
}
case Token.LITERALWITHDT:
LiteralWithDataTypeToken litdt = (LiteralWithDataTypeToken)lit;
try
{
if (litdt.DataType.StartsWith("<"))
{
dturi = litdt.DataType.Substring(1, litdt.DataType.Length - 2);
return context.Handler.CreateLiteralNode(litdt.Value, new Uri(Tools.ResolveUri(dturi, context.BaseUri.ToSafeString())));
}
else
{
dturi = Tools.ResolveQName(litdt.DataType, context.Namespaces, context.BaseUri);
return context.Handler.CreateLiteralNode(litdt.Value, new Uri(dturi));
}
}
catch (RdfException rdfEx)
{
throw new RdfParseException("Unable to resolve the Datatype '" + litdt.DataType + "' due to the following error:\n" + rdfEx.Message, litdt, rdfEx);
}
case Token.LITERALWITHLANG:
LiteralWithLanguageSpecifierToken langlit = (LiteralWithLanguageSpecifierToken)lit;
return context.Handler.CreateLiteralNode(langlit.Value, langlit.Language);
case Token.PLAINLITERAL:
//Attempt to infer Type
if (TurtleSpecsHelper.IsValidPlainLiteral(lit.Value))
{
if (TurtleSpecsHelper.IsValidDouble(lit.Value))
{
return context.Handler.CreateLiteralNode(lit.Value, new Uri(XmlSpecsHelper.XmlSchemaDataTypeDouble));
}
else if (TurtleSpecsHelper.IsValidInteger(lit.Value))
{
return context.Handler.CreateLiteralNode(lit.Value, new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger));
}
else if (TurtleSpecsHelper.IsValidDecimal(lit.Value))
{
return context.Handler.CreateLiteralNode(lit.Value, new Uri(XmlSpecsHelper.XmlSchemaDataTypeDecimal));
}
else
{
return context.Handler.CreateLiteralNode(lit.Value, new Uri(XmlSpecsHelper.XmlSchemaDataTypeBoolean));
}
}
else
{
throw ParserHelper.Error("The value '" + lit.Value + "' is not valid as a Plain Literal in Turtle", lit);
}
default:
throw ParserHelper.Error("Unexpected Token '" + lit.GetType().ToString() + "' encountered, expected a valid Literal Token to convert to a Node", lit);
}
}
示例5: PrintTrace
/// <summary>
/// Internal Helper Method for Tokeniser Tracing
/// </summary>
/// <param name="t"></param>
protected void PrintTrace(IToken t)
{
Console.WriteLine("[Lines " + t.StartLine + "-" + t.EndLine + " Columns " + t.StartPosition + "-" + t.EndPosition + "] " + t.GetType().Name + " " + t.Value);
}
示例6: TryParseNumericLiteral
//.........这里部分代码省略.........
}
case Token.LITERALWITHDT:
//Get the Data Type Uri
String dt = ((LiteralWithDataTypeToken)literal).DataType;
String dtUri;
if (dt.StartsWith("<"))
{
String baseUri = (this._baseUri == null) ? String.Empty : this._baseUri.ToString();
dtUri = Tools.ResolveUri(dt.Substring(1, dt.Length - 2), baseUri);
}
else
{
dtUri = Tools.ResolveQName(dt, this._nsmapper, this._baseUri);
}
//Return a Numeric Expression Term if it's an Integer/Decimal/Double
if (XmlSpecsHelper.XmlSchemaDataTypeInteger.Equals(dtUri) && SparqlSpecsHelper.IsInteger(literal.Value))
{
return new NumericExpressionTerm(Int32.Parse(literal.Value));
}
else if (XmlSpecsHelper.XmlSchemaDataTypeDecimal.Equals(dtUri) && SparqlSpecsHelper.IsDecimal(literal.Value))
{
return new NumericExpressionTerm(Decimal.Parse(literal.Value));
}
else if (XmlSpecsHelper.XmlSchemaDataTypeFloat.Equals(dtUri) && SparqlSpecsHelper.IsFloat(literal.Value))
{
return new NumericExpressionTerm(Single.Parse(literal.Value));
}
else if (XmlSpecsHelper.XmlSchemaDataTypeDouble.Equals(dtUri) && SparqlSpecsHelper.IsDouble(literal.Value))
{
return new NumericExpressionTerm(Double.Parse(literal.Value));
}
else
{
throw Error("The Literal '" + literal.Value + "' with Datatype URI '" + dtUri + "' is not a valid Integer, Decimal or Double", literal);
}
case Token.LITERAL:
//Check if there's a Datatype following the Literal
if (tokens.Count > 0)
{
IToken next = tokens.Peek();
if (next.TokenType == Token.HATHAT)
{
tokens.Dequeue();
//Should now see a DataTypeToken
DataTypeToken datatype = (DataTypeToken)tokens.Dequeue();
LiteralWithDataTypeToken dtlit = new LiteralWithDataTypeToken(literal, datatype);
//Self-recurse to save replicating code
return this.TryParseNumericLiteral(dtlit, tokens);
}
else
{
//Use Regex to see if it's a Integer/Decimal/Double
if (SparqlSpecsHelper.IsInteger(literal.Value))
{
return new NumericExpressionTerm(Int32.Parse(literal.Value));
}
else if (SparqlSpecsHelper.IsDecimal(literal.Value))
{
return new NumericExpressionTerm(Decimal.Parse(literal.Value));
}
else if (SparqlSpecsHelper.IsDouble(literal.Value))
{
return new NumericExpressionTerm(Double.Parse(literal.Value));
}
else
{
//Otherwise treat as a Node Expression
throw Error("The Literal '" + literal.Value + "' is not a valid Integer, Decimal or Double", literal);
}
}
}
else
{
//Use Regular Expressions to see what type it is
if (SparqlSpecsHelper.IsInteger(literal.Value))
{
return new NumericExpressionTerm(Int32.Parse(literal.Value));
}
else if (SparqlSpecsHelper.IsDecimal(literal.Value))
{
return new NumericExpressionTerm(Decimal.Parse(literal.Value));
}
else if (SparqlSpecsHelper.IsDouble(literal.Value))
{
return new NumericExpressionTerm(Double.Parse(literal.Value));
}
else
{
throw Error("The Literal '" + literal.Value + "' is not a valid Integer, Decimal or Double", literal);
}
}
default:
throw Error("Unexpected Token '" + literal.GetType().ToString() + "' encountered while trying to parse a Numeric Literal", literal);
}
}
示例7: ResolveUriOrQName
/// <summary>
/// Resolves a QName/Uri into a Uri using the Namespace Mapper and Base Uri provided
/// </summary>
/// <param name="t">QName/Uri to resolve</param>
/// <param name="nsmap">Namespace Map to resolve against</param>
/// <param name="baseUri">Base Uri to resolve against</param>
/// <returns></returns>
public static String ResolveUriOrQName(IToken t, INamespaceMapper nsmap, Uri baseUri)
{
if (t.TokenType == Token.QNAME)
{
return Tools.ResolveQName(t.Value, nsmap, baseUri);
}
else if (t.TokenType == Token.URI)
{
String uriBase = (baseUri == null) ? String.Empty : baseUri.ToString();
return Tools.ResolveUri(t.Value, uriBase);
}
else
{
throw new RdfParseException("Unable to resolve a '" + t.GetType().ToString() + "' Token into a URI", t);
}
}
示例8: CreateTriple
private Triple CreateTriple(IToken s, IToken p, IToken o, IGraph g)
{
INode subj, pred, obj;
switch (s.TokenType)
{
case Token.BLANKNODEWITHID:
subj = g.CreateBlankNode(s.Value.Substring(2));
break;
case Token.URI:
subj = g.CreateUriNode(new Uri(s.Value));
break;
default:
throw Error("Unexpected Token '" + s.GetType().ToString() + "' encountered, expected a Blank Node/URI as the Subject of a Triple", s);
}
switch (p.TokenType)
{
case Token.URI:
pred = g.CreateUriNode(new Uri(p.Value));
break;
default:
throw Error("Unexpected Token '" + p.GetType().ToString() + "' encountered, expected a URI as the Predicate of a Triple", p);
}
switch (o.TokenType)
{
case Token.BLANKNODEWITHID:
obj = g.CreateBlankNode(o.Value.Substring(2));
break;
case Token.LITERAL:
obj = g.CreateLiteralNode(o.Value);
break;
case Token.LITERALWITHDT:
String dtUri = ((LiteralWithDataTypeToken)o).DataType;
obj = g.CreateLiteralNode(o.Value, new Uri(dtUri.Substring(1, dtUri.Length - 2)));
break;
case Token.LITERALWITHLANG:
obj = g.CreateLiteralNode(o.Value, ((LiteralWithLanguageSpecifierToken)o).Language);
break;
case Token.URI:
obj = g.CreateUriNode(new Uri(o.Value));
break;
default:
throw Error("Unexpected Token '" + o.GetType().ToString() + "' encountered, expected a Blank Node/Literal/URI as the Object of a Triple", o);
}
return new Triple(subj, pred, obj, g);
}
示例9: TryResolveUri
internal static INode TryResolveUri(IResultsParserContext context, IToken t)
{
switch (t.TokenType)
{
case Token.URI:
try
{
String uri = Tools.ResolveUri(t.Value, String.Empty);
return context.Handler.CreateUriNode(UriFactory.Create(uri));
}
catch (UriFormatException formatEx)
{
throw new RdfParseException("Unable to resolve the URI '" + t.Value + "' due to the following error:\n" + formatEx.Message, t, formatEx);
}
catch (RdfException rdfEx)
{
throw new RdfParseException("Unable to resolve the URI '" + t.Value + "' due to the following error:\n" + rdfEx.Message, t, rdfEx);
}
default:
throw ParserHelper.Error("Unexpected Token '" + t.GetType().ToString() + "' encountered, expected a URI/QName Token to resolve into a URI", t);
}
}
示例10: Parse
public ISparqlPath Parse(SparqlQueryParserContext context, IToken first)
{
//Need to gather up all the Tokens which make up the path
int openBrackets = 0;
Queue<IToken> tokens = new Queue<IToken>();
IToken next;
LastPathItemType lastItem = LastPathItemType.None;
int lastSequencer = -1;
//Add the first token and set the initial last item type
tokens.Enqueue(first);
switch (first.TokenType)
{
case Token.LEFTBRACKET:
openBrackets = 1;
lastItem = LastPathItemType.Predicate;
break;
case Token.QNAME:
case Token.URI:
case Token.KEYWORDA:
lastItem = LastPathItemType.Predicate;
break;
case Token.HAT:
lastItem = LastPathItemType.Sequencer;
break;
case Token.NEGATION:
lastItem = LastPathItemType.Negation;
break;
default:
throw new RdfParseException("Unexpected Token '" + first.GetType().ToString() + "' encountered, this is not valid as the start of a property path");
}
while (true)
{
next = context.Tokens.Peek();
if (openBrackets > 0)
{
context.Tokens.Dequeue();
tokens.Enqueue(next);
if (next.TokenType == Token.RIGHTBRACKET)
{
openBrackets--;
//Groups are considered predicates for purposes of last item
lastItem = LastPathItemType.Predicate;
}
}
else
{
switch (next.TokenType)
{
case Token.LEFTBRACKET:
//Path Group
if (lastItem == LastPathItemType.Predicate || lastItem == LastPathItemType.Modifier)
{
//If it follows a Predicate/Modifier then this is likely a collection as the object of a
//Triple pattern so we stop
lastItem = LastPathItemType.End;
}
else if (lastItem == LastPathItemType.Sequencer || lastItem == LastPathItemType.Negation)
{
//This is a new Path Group if it follows a sequencer/negation
openBrackets++;
context.Tokens.Dequeue();
tokens.Enqueue(next);
lastItem = LastPathItemType.Predicate;
}
else
{
throw new RdfParseException("Path Groups can only follow path sequencing tokens", next);
}
break;
case Token.LEFTCURLYBRACKET:
//Explicit cardinality modifiers
if (lastItem != LastPathItemType.Predicate)
{
throw new RdfParseException("Cardinality Modifiers can only follow Predicates/Path Groups", next);
}
//Add the opening { to the tokens
context.Tokens.Dequeue();
tokens.Enqueue(next);
next = context.Tokens.Peek();
//Grab everything up to the next }
while (next.TokenType != Token.RIGHTCURLYBRACKET)
{
//If we see another { this is an error
if (next.TokenType == Token.LEFTCURLYBRACKET)
{
throw new RdfParseException("Nested Cardinality Modifiers for Paths are not permitted", next);
}
context.Tokens.Dequeue();
tokens.Enqueue(next);
next = context.Tokens.Peek();
}
//.........这里部分代码省略.........
示例11: TryParseAggregate
private SparqlVariable TryParseAggregate(SparqlQueryParserContext context, IToken agg)
{
if (context.SyntaxMode == SparqlQuerySyntax.Sparql_1_0) throw ParserHelper.Error("Aggregates are not supported in SPARQL 1.0", agg);
IToken next;
SparqlVariable var;
ISparqlAggregate aggregate;
//Check that the Token is an Aggregate Keyword Token
switch (agg.TokenType)
{
case Token.AVG:
case Token.COUNT:
case Token.GROUPCONCAT:
case Token.MAX:
case Token.MEDIAN:
case Token.MIN:
case Token.MODE:
case Token.NMAX:
case Token.NMIN:
case Token.SAMPLE:
case Token.SUM:
//OK
break;
default:
throw ParserHelper.Error("Cannot parse an Aggregate since '" + agg.GetType().ToString() + "' is not an Aggregate Keyword Token", agg);
}
//Gather up the Tokens and call into the Expression Parser to get this parsed
Queue<IToken> tokens = new Queue<IToken>();
tokens.Enqueue(agg);
int openBrackets = 0;
do
{
next = context.Tokens.Dequeue();
if (next.TokenType == Token.LEFTBRACKET)
{
openBrackets++;
}
else if (next.TokenType == Token.RIGHTBRACKET)
{
openBrackets--;
}
tokens.Enqueue(next);
} while (openBrackets > 0);
context.ExpressionParser.AllowAggregates = true;
ISparqlExpression aggExpr = context.ExpressionParser.Parse(tokens);
context.ExpressionParser.AllowAggregates = false;
if (aggExpr is AggregateExpressionTerm)
{
aggregate = ((AggregateExpressionTerm)aggExpr).Aggregate;
}
else if (aggExpr is NonNumericAggregateExpressionTerm)
{
aggregate = ((NonNumericAggregateExpressionTerm)aggExpr).Aggregate;
}
else
{
throw new RdfParseException("Unexpected expression was parsed when an Aggregate was expected: " + aggExpr.ToString());
}
//See if there is an alias
String alias = "Result";
next = context.Tokens.Peek();
if (next.TokenType == Token.AS)
{
context.Tokens.Dequeue();
next = context.Tokens.Dequeue();
if (next.TokenType != Token.VARIABLE)
{
throw ParserHelper.Error("Unexpected Token '" + next.GetType().ToString() + "', expected a Variable Token after an AS Keyword to act as an aliased name for the Aggregate", next);
}
alias = next.Value.Substring(1);
}
else
{
if (context.SyntaxMode != SparqlQuerySyntax.Extended) throw ParserHelper.Error("Unexpected Token '" + next.GetType().ToString() + "' encountered, expected an AS keyword after an Aggregate", next);
int nextID = context.NextAliasID;
if (nextID > 0) alias += nextID.ToString();
while (context.Query.Variables.Any(v => v.Name.Equals(alias)))
{
alias = "Result" + context.NextAliasID;
}
this.RaiseWarning("No AS ?variable given for the Aggregate " + aggregate.ToString() + " so assigning alias '" + alias + "'");
}
var = new SparqlVariable(alias, aggregate);
return var;
}
示例12: TryCreatePatternItem
//.........这里部分代码省略.........
switch (t.TokenType)
{
case Token.VARIABLE:
//Variables accept any Node as a substitution
return new VariablePattern(t.Value);
case Token.URI:
//Uri uses a Node Match
if (t.Value.StartsWith("_:"))
{
return new FixedBlankNodePattern(t.Value);
}
else
{
String uri = Tools.ResolveUri(t.Value, context.Query.BaseUri.ToSafeString());
u = new Uri(uri);
//if (Options.UriNormalization)
//{
return new NodeMatchPattern(new UriNode(null, u));
//}
//else
//{
// return new NodeMatchPattern(new NonNormalizedUriNode(null, uri));
//}
}
case Token.QNAME:
//QName uses a Node Match
//if (Options.UriNormalization)
//{
return new NodeMatchPattern(new UriNode(null, this.ResolveQName(context, t.Value)));
//}
//else
//{
// return new NodeMatchPattern(new NonNormalizedUriNode(null, Tools.ResolveQName(t.Value, context.Query.NamespaceMap, context.Query.BaseUri)));
//}
case Token.LITERAL:
case Token.LONGLITERAL:
//Literals use Node Matches
return new NodeMatchPattern(new NonNormalizedLiteralNode(null, t.Value));
case Token.PLAINLITERAL:
//Plain Literals either use an inferred Literal Node Match
//We know it must be one of the inferrable types or the Parser would have failed at the Tokenisation stage for the Literal
if (TurtleSpecsHelper.IsValidDouble(t.Value))
{
//Double - Check first since to be considered a double must contain an exponent so is unique compared to
//the other two numeric types
return new NodeMatchPattern(new LiteralNode(null, t.Value, new Uri(XmlSpecsHelper.XmlSchemaDataTypeDouble)));
}
else if (TurtleSpecsHelper.IsValidInteger(t.Value))
{
//Integer - Check before decimal as any valid integer is a valid decimal
return new NodeMatchPattern(new LiteralNode(null, t.Value, new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger)));
}
else if (TurtleSpecsHelper.IsValidDecimal(t.Value))
{
//Decimal - Check last since any valid integer is also a valid decimal
return new NodeMatchPattern(new LiteralNode(null, t.Value, new Uri(XmlSpecsHelper.XmlSchemaDataTypeDecimal)));
}
else
{
//Boolean
return new NodeMatchPattern(new LiteralNode(null, t.Value, new Uri(XmlSpecsHelper.XmlSchemaDataTypeBoolean)));
}
case Token.LITERALWITHDT:
//Literal with Datatype use Node Matches
LiteralWithDataTypeToken litdt = (LiteralWithDataTypeToken)t;
if (litdt.DataType.StartsWith("<"))
{
baseUri = (context.Query.BaseUri == null) ? String.Empty : context.Query.BaseUri.ToString();
u = new Uri(Tools.ResolveUri(litdt.DataType.Substring(1, litdt.DataType.Length - 2), baseUri));
return new NodeMatchPattern(new NonNormalizedLiteralNode(null, litdt.Value, u));
}
else
{
//Resolve the QName
return new NodeMatchPattern(new NonNormalizedLiteralNode(null, litdt.Value, this.ResolveQName(context, litdt.DataType)));
}
case Token.LITERALWITHLANG:
//Literal with Lang Spec use Node Matches
LiteralWithLanguageSpecifierToken litls = (LiteralWithLanguageSpecifierToken)t;
return new NodeMatchPattern(new NonNormalizedLiteralNode(null, litls.Value, litls.Language));
case Token.BLANKNODEWITHID:
//Blanks accept any Blank
return new BlankNodePattern(t.Value.Substring(2));
case Token.KEYWORDA:
return new NodeMatchPattern(new UriNode(null, new Uri(NamespaceMapper.RDF + "type")));
default:
throw ParserHelper.Error("Unable to Convert a '" + t.GetType().ToString() + "' to a Pattern Item in a Triple Pattern", t);
}
}
示例13: GetTokenValue
private string GetTokenValue(IToken token)
{
Type t = token.GetType();
PropertyInfo[] infos = t.GetProperties(BindingFlags.FlattenHierarchy | BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public);
Dictionary<string, string> map = new Dictionary<string, string>();
foreach (PropertyInfo info in infos)
{
if (!(new string[] { "StartPosition", "StopPosition", "IsValid", "ScanError", "SourceString" }).Contains(info.Name))
{
object value = info.GetValue(token, null);
map[info.Name] = String.Format("{0}", value);
}
}
if ((map.Count == 1) && map.ContainsKey("Value"))
return map["Value"];
StringBuilder sb = new StringBuilder();
foreach (var pair in map)
{
if (sb.Length != 0)
sb.Append(", ");
sb.AppendFormat("{0}: {1}", pair.Key, pair.Value);
}
return sb.ToString();
}