Ejemplo n.º 1
0
        private RDFGraph DeserializateGraph(RDFModelEnums.RDFFormats format)
        {
            try
            {
                switch (format)
                {
                case RDFModelEnums.RDFFormats.NTriples:
                    return(RDFGraph.FromFile(RDFModelEnums.RDFFormats.NTriples, "graphs/NTriples.txt"));

                case RDFModelEnums.RDFFormats.RdfXml:
                    return(RDFGraph.FromFile(RDFModelEnums.RDFFormats.RdfXml, "graphs/RdfXml.txt"));

                case RDFModelEnums.RDFFormats.TriX:
                    return(RDFGraph.FromFile(RDFModelEnums.RDFFormats.TriX, "graphs/TriX.txt"));

                case RDFModelEnums.RDFFormats.Turtle:
                    return(RDFGraph.FromFile(RDFModelEnums.RDFFormats.Turtle, "graphs/Turtle.txt"));

                default:
                    return(null);
                }
            }
            catch (RDFModelException ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a graph from a stream of the given RDF format.
        /// </summary>
        public static RDFGraph FromStream(RDFModelEnums.RDFFormats rdfFormat, Stream inputStream)
        {
            if (inputStream != null)
            {
                switch (rdfFormat)
                {
                case RDFModelEnums.RDFFormats.NTriples:
                    return(RDFNTriples.Deserialize(inputStream));

                case RDFModelEnums.RDFFormats.RdfXml:
                    return(RDFXml.Deserialize(inputStream));

                case RDFModelEnums.RDFFormats.TriX:
                    return(RDFTriX.Deserialize(inputStream));

                case RDFModelEnums.RDFFormats.Turtle:
                    return(RDFTurtle.Deserialize(inputStream));

                default:
                    throw new NotImplementedException();
                    break;
                }
            }
            throw new RDFModelException("Cannot read RDF graph from stream because given \"inputStream\" parameter is null.");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Writes the graph into a stream in the given RDF format.
        /// </summary>
        public void ToStream(RDFModelEnums.RDFFormats rdfFormat, Stream outputStream)
        {
            if (outputStream != null)
            {
                switch (rdfFormat)
                {
                case RDFModelEnums.RDFFormats.NTriples:
                    RDFNTriples.Serialize(this, outputStream);
                    break;

                case RDFModelEnums.RDFFormats.RdfXml:
                    RDFXml.Serialize(this, outputStream);
                    break;

                case RDFModelEnums.RDFFormats.TriX:
                    RDFTriX.Serialize(this, outputStream);
                    break;

                case RDFModelEnums.RDFFormats.Turtle:
                    RDFTurtle.Serialize(this, outputStream);
                    break;

                default:
                    throw new NotImplementedException();
                    break;
                }
            }
            else
            {
                throw new RDFModelException("Cannot write RDF graph to stream because given \"outputStream\" parameter is null.");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a graph from a file of the given RDF format.
        /// </summary>
        public static RDFGraph FromFile(RDFModelEnums.RDFFormats rdfFormat, String filepath)
        {
            if (!String.IsNullOrEmpty(filepath))
            {
                if (File.Exists(filepath))
                {
                    switch (rdfFormat)
                    {
                    case RDFModelEnums.RDFFormats.NTriples:
                        return(RDFNTriples.Deserialize(filepath));

                    case RDFModelEnums.RDFFormats.RdfXml:
                        return(RDFXml.Deserialize(filepath));

                    case RDFModelEnums.RDFFormats.TriX:
                        return(RDFTriX.Deserialize(filepath));

                    case RDFModelEnums.RDFFormats.Turtle:
                        return(RDFTurtle.Deserialize(filepath));

                    default:
                        throw new NotImplementedException();
                        break;
                    }
                }
                throw new RDFModelException("Cannot read RDF graph from file because given \"filepath\" parameter (" + filepath + ") does not indicate an existing file.");
            }
            throw new RDFModelException("Cannot read RDF graph from file because given \"filepath\" parameter is null or empty.");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Writes the graph into a file in the given RDF format.
        /// </summary>
        public void ToFile(RDFModelEnums.RDFFormats rdfFormat, String filepath)
        {
            if (filepath != null && filepath.Trim() != String.Empty)
            {
                switch (rdfFormat)
                {
                case RDFModelEnums.RDFFormats.NTriples:
                    RDFNTriples.Serialize(this, filepath);
                    break;

                case RDFModelEnums.RDFFormats.RdfXml:
                    RDFXml.Serialize(this, filepath);
                    break;

                case RDFModelEnums.RDFFormats.TriX:
                    RDFTriX.Serialize(this, filepath);
                    break;

                case RDFModelEnums.RDFFormats.Turtle:
                    RDFTurtle.Serialize(this, filepath);
                    break;
                }
            }
            else
            {
                throw new RDFModelException("Cannot write RDF graph to file because given \"filepath\" parameter is null or empty.");
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Writes the graph into a file in the given RDF format.
        /// </summary>
        public void ToFile(RDFModelEnums.RDFFormats rdfFormat, String filepath)
        {
            if (!String.IsNullOrEmpty(filepath))
            {
                switch (rdfFormat)
                {
                case RDFModelEnums.RDFFormats.NTriples:
                    RDFNTriples.Serialize(this, filepath);
                    break;

                case RDFModelEnums.RDFFormats.RdfXml:
                    RDFXml.Serialize(this, filepath);
                    break;

                case RDFModelEnums.RDFFormats.TriX:
                    RDFTriX.Serialize(this, filepath);
                    break;

                case RDFModelEnums.RDFFormats.Turtle:
                    RDFTurtle.Serialize(this, filepath);
                    break;

                default:
                    throw new NotImplementedException();
                    break;
                }
            }
            else
            {
                throw new RDFModelException("Cannot write RDF graph to file because given \"filepath\" parameter is null or empty.");
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a graph from a file of the given RDF format.
        /// </summary>
        public static RDFGraph FromFile(RDFModelEnums.RDFFormats rdfFormat, String filepath)
        {
            if (filepath != null)
            {
                if (File.Exists(filepath))
                {
                    switch (rdfFormat)
                    {
                    case RDFModelEnums.RDFFormats.NTriples:
                        return(RDFNTriples.Deserialize(filepath));

                    case RDFModelEnums.RDFFormats.RdfXml:
                        return(RDFXml.Deserialize(filepath));

                    case RDFModelEnums.RDFFormats.TriX:
                        return(RDFTriX.Deserialize(filepath));

                    case RDFModelEnums.RDFFormats.Turtle:
                        throw new RDFModelException("Cannot read RDF graph from file because Turtle format is not supported. What about joining the project to contribute it?");
                    }
                }
                throw new RDFModelException("Cannot read RDF graph from file because given \"filepath\" parameter (" + filepath + ") does not indicate an existing file.");
            }
            throw new RDFModelException("Cannot read RDF graph from file because given \"filepath\" parameter is null or empty.");
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a graph from a stream of the given RDF format.
        /// </summary>
        public static RDFGraph FromStream(RDFModelEnums.RDFFormats rdfFormat, Stream inputStream)
        {
            if (inputStream != null)
            {
                switch (rdfFormat)
                {
                case RDFModelEnums.RDFFormats.NTriples:
                    return(RDFNTriples.Deserialize(inputStream));

                case RDFModelEnums.RDFFormats.RdfXml:
                    return(RDFXml.Deserialize(inputStream));

                case RDFModelEnums.RDFFormats.TriX:
                    return(RDFTriX.Deserialize(inputStream));

                case RDFModelEnums.RDFFormats.Turtle:
                    throw new RDFModelException("Cannot read RDF graph from stream because Turtle format is not supported. What about joining the project to contribute it?");
                }
            }
            throw new RDFModelException("Cannot read RDF graph from stream because given \"filepath\" parameter is null.");
        }
Ejemplo n.º 9
0
        internal static RDFGraph FromStream(RDFModelEnums.RDFFormats rdfFormat, Stream inputStream, Uri graphContext)
        {
            if (inputStream != null)
            {
                switch (rdfFormat)
                {
                case RDFModelEnums.RDFFormats.RdfXml:
                    return(RDFXml.Deserialize(inputStream, graphContext));

                case RDFModelEnums.RDFFormats.Turtle:
                    return(RDFTurtle.Deserialize(inputStream, graphContext));

                case RDFModelEnums.RDFFormats.NTriples:
                    return(RDFNTriples.Deserialize(inputStream, graphContext));

                case RDFModelEnums.RDFFormats.TriX:
                    return(RDFTriX.Deserialize(inputStream, graphContext));
                }
            }
            throw new RDFModelException("Cannot read RDF graph from stream because given \"inputStream\" parameter is null.");
        }
Ejemplo n.º 10
0
        private void SerializeGraph(RDFGraph graph, RDFModelEnums.RDFFormats format)
        {
            // create file path
            DirectoryInfo di = Directory.CreateDirectory("graphs");

            switch (format)
            {
            case RDFModelEnums.RDFFormats.NTriples:
                graph.ToFile(RDFModelEnums.RDFFormats.NTriples, "graphs/NTriples.txt");
                break;

            case RDFModelEnums.RDFFormats.RdfXml:
                graph.ToFile(RDFModelEnums.RDFFormats.RdfXml, "graphs/RdfXml.txt");
                break;

            case RDFModelEnums.RDFFormats.TriX:
                graph.ToFile(RDFModelEnums.RDFFormats.TriX, "graphs/TriX.txt");
                break;

            case RDFModelEnums.RDFFormats.Turtle:
                graph.ToFile(RDFModelEnums.RDFFormats.Turtle, "graphs/Turtle.txt");
                break;
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Creates a graph from a stream of the given RDF format.
 /// </summary>
 public static RDFGraph FromStream(RDFModelEnums.RDFFormats rdfFormat, Stream inputStream) => FromStream(rdfFormat, inputStream, null);
Ejemplo n.º 12
0
        public static void Convert(RDFModelEnums.RDFFormats formatSource, FileInfo fileSource, RDFModelEnums.RDFFormats formatDestination, FileInfo fileDestination)
        {
            RDFGraph graph = RDFGraph.FromFile(formatSource, fileSource.FullName);

            graph.ToFile(formatDestination, fileDestination.FullName);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Asynchronously reads a graph from a stream of the given RDF format.
 /// </summary>
 public static Task <RDFGraph> FromStreamAsync(RDFModelEnums.RDFFormats rdfFormat, Stream inputStream)
 => Task.Run(() => FromStream(rdfFormat, inputStream));
Ejemplo n.º 14
0
 /// <summary>
 /// Asynchronously reads a graph from a file of the given RDF format.
 /// </summary>
 public static Task <RDFGraph> FromFileAsync(RDFModelEnums.RDFFormats rdfFormat, string filepath)
 => Task.Run(() => FromFile(rdfFormat, filepath));
Ejemplo n.º 15
0
 /// <summary>
 /// Asynchronously writes the graph into a stream in the given RDF format.
 /// </summary>
 public Task ToStreamAsync(RDFModelEnums.RDFFormats rdfFormat, Stream outputStream)
 => Task.Run(() => ToStream(rdfFormat, outputStream));
Ejemplo n.º 16
0
 /// <summary>
 /// Asynchronously writes the graph into a file in the given RDF format.
 /// </summary>
 public Task ToFileAsync(RDFModelEnums.RDFFormats rdfFormat, string filepath)
 => Task.Run(() => ToFile(rdfFormat, filepath));