本文整理汇总了C#中IRdfHandler.CreateBlankNode方法的典型用法代码示例。如果您正苦于以下问题:C# IRdfHandler.CreateBlankNode方法的具体用法?C# IRdfHandler.CreateBlankNode怎么用?C# IRdfHandler.CreateBlankNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRdfHandler
的用法示例。
在下文中一共展示了IRdfHandler.CreateBlankNode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: HandleTriple
/// <summary>
/// Creates and handles a triple
/// </summary>
/// <param name="handler">Handler</param>
/// <param name="subject">Subject</param>
/// <param name="predicate">Predicate</param>
/// <param name="obj">Object</param>
/// <param name="datatype">Object Datatype</param>
/// <returns>True if parsing should continue, false otherwise</returns>
bool HandleTriple(IRdfHandler handler, string subject, string predicate, string obj, string datatype, bool isLiteral)
{
INode subjectNode;
if (subject.StartsWith("_"))
{
string nodeId = subject.Substring(subject.IndexOf(":") + 1);
subjectNode = handler.CreateBlankNode(nodeId);
}
else
{
subjectNode = handler.CreateUriNode(new Uri(subject));
}
INode predicateNode = handler.CreateUriNode(new Uri(predicate));
INode objNode;
if (isLiteral)
{
objNode = (datatype == null) ? handler.CreateLiteralNode((string)obj) : handler.CreateLiteralNode((string)obj, new Uri(datatype));
}
else
{
if (obj.StartsWith("_"))
{
string nodeId = obj.Substring(obj.IndexOf(":") + 1);
objNode = handler.CreateBlankNode(nodeId);
}
else
{
objNode = handler.CreateUriNode(new Uri(obj));
}
}
return handler.HandleTriple(new Triple(subjectNode, predicateNode, objNode));
}
示例3: HandleTriple
/// <summary>
/// Creates and handles a triple
/// </summary>
/// <param name="handler">Handler</param>
/// <param name="subject">Subject</param>
/// <param name="predicate">Predicate</param>
/// <param name="obj">Object</param>
/// <param name="datatype">Object Datatype</param>
/// <param name="isLiteral">isLiteral Object</param>
/// <returns>True if parsing should continue, false otherwise</returns>
bool HandleTriple(IRdfHandler handler, string subject, string predicate, string obj, string datatype, bool isLiteral)
{
INode subjectNode;
if (subject.StartsWith("_"))
{
string nodeId = subject.Substring(subject.IndexOf(":") + 1);
subjectNode = handler.CreateBlankNode(nodeId);
}
else
{
subjectNode = handler.CreateUriNode(new Uri(subject));
}
INode predicateNode = handler.CreateUriNode(new Uri(predicate));
INode objNode;
if (isLiteral)
{
if (datatype == "http://www.w3.org/2001/XMLSchema#boolean")
{
// sometimes newtonsoft.json appears to return boolean as string True and dotNetRdf doesn't appear to recognize that
obj = ((string)obj).ToLowerInvariant();
}
objNode = (datatype == null) ? handler.CreateLiteralNode((string)obj) : handler.CreateLiteralNode((string)obj, new Uri(datatype));
}
else
{
if (obj.StartsWith("_"))
{
string nodeId = obj.Substring(obj.IndexOf(":") + 1);
objNode = handler.CreateBlankNode(nodeId);
}
else
{
objNode = handler.CreateUriNode(new Uri(obj));
}
}
return handler.HandleTriple(new Triple(subjectNode, predicateNode, objNode));
}
示例4: TryParseNode
private INode TryParseNode(XmlReader reader, IRdfHandler handler, TripleSegment segment)
{
//Only need to Read() if getting the Subject
//The previous calls will have resulted in us already reading to the start element for this node
if (segment == TripleSegment.Subject) reader.Read();
if (reader.NodeType != XmlNodeType.Element)
{
if (reader.NodeType == XmlNodeType.EndElement) throw Error("Unexpected end element while trying to parse the nodes of a <triple> element", reader);
}
if (reader.Name.Equals("uri"))
{
return handler.CreateUriNode(new Uri(reader.ReadInnerXml()));
}
else if (reader.Name.Equals("id"))
{
if (segment == TripleSegment.Predicate) throw Error("Unexpected element <" + reader.Name + "> encountered, expected a <uri> element as the Predicate of a Triple", reader);
return handler.CreateBlankNode(reader.ReadInnerXml());
}
else if (reader.Name.Equals("plainLiteral"))
{
if (segment == TripleSegment.Subject) throw Error("Unexpected element <" + reader.Name + "> encountered, expected a <id>/<uri> element as the Subject of a Triple", reader);
if (reader.AttributeCount > 0)
{
String lang = String.Empty;
for (int i = 0; i < reader.AttributeCount; i++)
{
reader.MoveToNextAttribute();
if (reader.Name.Equals("xml:lang")) lang = reader.Value;
}
reader.MoveToContent();
if (!lang.Equals(String.Empty))
{
return handler.CreateLiteralNode(reader.ReadInnerXml(), lang);
}
else
{
return handler.CreateLiteralNode(reader.ReadInnerXml());
}
}
else
{
return handler.CreateLiteralNode(reader.ReadInnerXml());
}
}
else if (reader.Name.Equals("typedLiteral"))
{
if (reader.AttributeCount > 0)
{
Uri dtUri = null;
for (int i = 0; i < reader.AttributeCount; i++)
{
reader.MoveToNextAttribute();
if (reader.Name.Equals("datatype")) dtUri = new Uri(reader.Value);
}
if (dtUri == null) throw Error("<typedLiteral> element does not have the required datatype attribute", reader);
reader.MoveToContent();
return handler.CreateLiteralNode(reader.ReadInnerXml(), dtUri);
}
else
{
throw Error("<typedLiteral> element does not have the required datatype attribute", reader);
}
}
else
{
throw Error("Unexpected element <" + reader.Name + "> encountered, expected a <id>/<uri>/<plainLiteral>/<typedLiteral> element as part of a Triple", reader);
}
}
示例5: TryParseTriple
private void TryParseTriple(XmlNode tripleEl, IRdfHandler handler, Uri graphUri)
{
//Verify Node Name
if (!tripleEl.Name.Equals("triple"))
{
throw new RdfParseException("Unexpected Element <" + tripleEl.Name + "> encountered, only an optional <uri> element followed by zero/more <triple> elements are permitted within a <graph> element");
}
//Verify number of Child Nodes
if (!tripleEl.HasChildNodes) throw new RdfParseException("<triple> element has no child nodes - 3 child nodes are expected");
if (tripleEl.ChildNodes.Count < 3) throw new RdfParseException("<triple> element has too few child nodes (" + tripleEl.ChildNodes.Count + ") - 3 child nodes are expected");
if (tripleEl.ChildNodes.Count > 3) throw new RdfParseException("<triple> element has too many child nodes (" + tripleEl.ChildNodes.Count + ") - 3 child nodes are expected");
//Get the 3 Child Nodes
XmlNode subjEl, predEl, objEl;
subjEl = tripleEl.ChildNodes[0];
predEl = tripleEl.ChildNodes[1];
objEl = tripleEl.ChildNodes[2];
//Parse XML Nodes into RDF Nodes
INode subj, pred, obj;
if (subjEl.Name.Equals("uri"))
{
subj = handler.CreateUriNode(new Uri(subjEl.InnerText));
}
else if (subjEl.Name.Equals("id"))
{
subj = handler.CreateBlankNode(subjEl.InnerText);
}
else
{
throw Error("Unexpected element <" + subjEl.Name + "> encountered, expected a <id>/<uri> element as the Subject of a Triple", subjEl);
}
if (predEl.Name.Equals("uri"))
{
pred = handler.CreateUriNode(new Uri(predEl.InnerText));
}
else
{
throw Error("Unexpected element <" + predEl.Name + "> encountered, expected a <uri> element as the Predicate of a Triple", subjEl);
}
if (objEl.Name.Equals("uri"))
{
obj = handler.CreateUriNode(new Uri(objEl.InnerText));
}
else if (objEl.Name.Equals("id"))
{
obj = handler.CreateBlankNode(objEl.InnerText);
}
else if (objEl.Name.Equals("plainLiteral"))
{
if (objEl.Attributes.GetNamedItem("xml:lang") != null)
{
obj = handler.CreateLiteralNode(objEl.InnerText, objEl.Attributes["xml:lang"].Value);
}
else
{
obj = handler.CreateLiteralNode(objEl.InnerText);
}
}
else if (objEl.Name.Equals("typedLiteral"))
{
if (objEl.Attributes.GetNamedItem("datatype") != null)
{
Uri dtUri = new Uri(objEl.Attributes["datatype"].Value);
if (objEl.FirstChild.NodeType == XmlNodeType.Text)
{
obj = handler.CreateLiteralNode(objEl.InnerText, dtUri);
}
else if (objEl.FirstChild.NodeType == XmlNodeType.CDATA)
{
obj = handler.CreateLiteralNode(objEl.FirstChild.InnerXml, dtUri);
}
else
{
obj = handler.CreateLiteralNode(objEl.InnerText, dtUri);
}
}
else
{
throw Error("<typedLiteral> element does not have the required datatype attribute", objEl);
}
}
else
{
throw Error("Unexpected element <" + objEl.Name + "> encountered, expected a <id>/<uri>/<plainLiteral>/<typedLiteral> element as the Object of a Triple", subjEl);
}
//Assert the resulting Triple
if (!handler.HandleTriple(new Triple(subj, pred, obj, graphUri))) throw ParserHelper.Stop(); ;
}
示例6: HandleTriple
private static void HandleTriple(IRdfHandler handler, string subject, string predicate, string obj, string datatype, bool isLiteral)
{
INode subjectNode = (subject.StartsWith("_") ? (INode)handler.CreateBlankNode(subject.Substring(2)) : handler.CreateUriNode(new Uri(subject)));
INode predicateNode = handler.CreateUriNode(new Uri(predicate));
INode objNode;
if (isLiteral)
{
if (datatype == "http://www.w3.org/2001/XMLSchema#boolean")
{
obj = obj.ToLowerInvariant();
}
objNode = (datatype == null ? handler.CreateLiteralNode(obj) : handler.CreateLiteralNode(obj, new Uri(datatype)));
}
else
{
objNode = (obj.StartsWith("_") ? (INode)handler.CreateBlankNode(obj.Substring(2)) : handler.CreateUriNode(new Uri(obj)));
}
if (!handler.HandleTriple(new Triple(subjectNode, predicateNode, objNode)))
{
throw new InvalidOperationException(String.Format("Could not add triple {0} {1} {2} .", subjectNode, predicateNode, objNode));
}
}