2using System.Collections.Generic;
4using System.Threading.Tasks;
26 private static readonly
string[] TurtleContentTypes =
new string[]
29 "application/x-turtle"
37 private static readonly
string[] TurtleFileExtensions =
new string[]
60 if (Array.IndexOf(TurtleContentTypes, ContentType) >= 0)
81 public Task<object>
DecodeAsync(
string ContentType,
byte[] Data, Encoding Encoding, KeyValuePair<string, string>[] Fields, Uri BaseUri)
85 return Task.FromResult<
object>(Parsed);
121 public Task<KeyValuePair<byte[], string>>
EncodeAsync(
object Object, Encoding Encoding, params
string[] AcceptedContentTypes)
123 if (Encoding is
null)
124 Encoding = Encoding.UTF8;
133 throw new ArgumentException(
"Unable to encode object.", nameof(Object));
135 StringBuilder sb =
new StringBuilder();
148 Text = sb.ToString();
151 byte[] Bin = Encoding.GetBytes(Text);
152 string ContentType = TurtleContentTypes[0] +
"; charset=" + Encoding.WebName;
154 return Task.FromResult(
new KeyValuePair<
byte[],
string>(Bin, ContentType));
165 if (
string.Compare(FileExtension, TurtleFileExtensions[0],
true) == 0)
167 ContentType = TurtleContentTypes[0];
185 if (Array.IndexOf(TurtleContentTypes, ContentType) >= 0)
187 FileExtension = TurtleFileExtensions[0];
192 FileExtension =
null;
Helps with parsing of commong data types.
static string GetString(byte[] Data, Encoding DefaultEncoding)
Gets a string from its binary representation, taking any Byte Order Mark (BOM) into account.
Static class managing encoding and decoding of internet content.
static bool IsAccepted(string ContentType, params string[] AcceptedContentTypes)
Checks if a given content type is acceptable.
Encoder and Decoder of semantic information in Turtle Documents.
Task< KeyValuePair< byte[], string > > EncodeAsync(object Object, Encoding Encoding, params string[] AcceptedContentTypes)
Encodes an object
const string DefaultContentType
text/turtle
string[] FileExtensions
Supported file extensions.
bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
If the encoder encodes a specific object.
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of content of a given file extension.
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of content of a given content type.
TurtleCodec()
Encoder and Decoder of semantic information in Turtle Documents.
Task< object > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri)
Decodes an object
string[] ContentTypes
Supported Internet Content Types.
const string DefaultExtension
ttl
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes content of a given Internet Content Type.
Contains semantic information stored in a turtle document. https://www.w3.org/TR/rdf12-turtle/ https:...
Basic interface for Internet Content decoders. A class implementing this interface and having a defau...
Basic interface for Internet Content encoders. A class implementing this interface and having a defau...
Interface for semantic models.
Interface for semantic triples.
ISemanticElement Object
Object element
ISemanticElement Predicate
Predicate element
ISemanticElement Subject
Subject element
BlankNodeIdMode
How blank node IDs are generated