Exemple #1
0
        /// <summary>
        /// Exports the given named graph to a file with the given filename.
        /// The format is determined by the file extension.
        /// Currently available are: .grs/.grsi or .gxl or .xmi.
        /// Optionally suffixed by .gz; in this case they are saved gzipped.
        /// Any errors will be reported by exception.
        /// </summary>
        /// <param name="graph">The named graph to export.
        /// The .grs/.grsi exporter is exporting the names/including the names; import will return a named graph again.
        /// The .gxl exporter is exporting without the names, which is equivalent of calling the non-named graph export.</param>
        /// The .xmi exporter is using the names as xmi ids.</param>
        /// <param name="filenameParameters">The names of the files to be exported.
        /// The first must be a filename, the following may be used for giving export parameters
        /// (in fact currently no exporter supports multiple files).</param>
        public static void Export(INamedGraph graph, List <String> filenameParameters)
        {
            String       first  = ListGet(filenameParameters, 0);
            StreamWriter writer = null;

            if (first.EndsWith(".gz", StringComparison.InvariantCultureIgnoreCase))
            {
                FileStream filewriter = new FileStream(first, FileMode.OpenOrCreate, FileAccess.Write);
                writer = new StreamWriter(new GZipStream(filewriter, CompressionMode.Compress));
                first  = first.Substring(0, first.Length - 3);
            }
            else
            {
                writer = new StreamWriter(first);
            }

            using (writer)
            {
                if (first.EndsWith(".gxl", StringComparison.InvariantCultureIgnoreCase))
                {
                    GXLExport.Export(graph, writer);
                }
                else if (first.EndsWith(".grs", StringComparison.InvariantCultureIgnoreCase) ||
                         first.EndsWith(".grsi", StringComparison.InvariantCultureIgnoreCase))
                {
                    GRSExport.Export(graph, writer);
                }
                else if (first.EndsWith(".xmi", StringComparison.InvariantCultureIgnoreCase))
                {
                    XMIExport.Export(graph, writer);
                }
                else if (first.EndsWith(".grg", StringComparison.InvariantCultureIgnoreCase))
                {
                    GRGExport.Export(graph, writer);
                }
                else
                {
                    throw new NotSupportedException("File format not supported");
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Exports the given graph to a GRS file with the given filename.
 /// Any errors will be reported by exception.
 /// </summary>
 /// <param name="graph">The graph to export. Must be a named graph.</param>
 /// <param name="exportFilename">The filename for the exported file.</param>
 public static void Export(INamedGraph graph, String exportFilename)
 {
     using (GRSExport export = new GRSExport(exportFilename))
         export.Export(graph);
 }
Exemple #3
0
 /// <summary>
 /// Exports the given graph to the file given by the stream writer in grs format.
 /// Any errors will be reported by exception.
 /// </summary>
 /// <param name="graph">The graph to export. Must be a named graph.</param>
 /// <param name="writer">The stream writer to export to.</param>
 public static void Export(INamedGraph graph, StreamWriter writer)
 {
     using (GRSExport export = new GRSExport(writer))
         export.Export(graph);
 }
Exemple #4
0
 /// <summary>
 /// Exports the given graph to the file given by the stream writer in grs format.
 /// Any errors will be reported by exception.
 /// </summary>
 /// <param name="graph">The graph to export. Must be a named graph.</param>
 /// <param name="writer">The stream writer to export to.</param>
 /// <param name="nonewgraph">If true, the new graph command is not emitted.</param>
 /// <param name="typesToAttributesToSkip">Gives a dictionary with type names containing a dictionary with attribute names that are not to be emitted</param>
 public static void Export(INamedGraph graph, StreamWriter writer, bool noNewGraph, Dictionary <String, Dictionary <String, String> > typesToAttributesToSkip)
 {
     using (GRSExport export = new GRSExport(writer))
         export.Export(graph, noNewGraph, typesToAttributesToSkip);
 }
Exemple #5
0
 /// <summary>
 /// Exports the given graph to a GRS file with the given filename.
 /// Any errors will be reported by exception.
 /// </summary>
 /// <param name="graph">The graph to export. Must be a named graph.</param>
 /// <param name="exportFilename">The filename for the exported file.</param>
 /// <param name="nonewgraph">If true, the new graph command is not emitted.</param>
 /// <param name="typesToAttributesToSkip">Gives a dictionary with type names containing a dictionary with attribute names that are not to be emitted</param>
 public static void Export(INamedGraph graph, String exportFilename, bool noNewGraph, Dictionary <String, Dictionary <String, String> > typesToAttributesToSkip)
 {
     using (GRSExport export = new GRSExport(exportFilename))
         export.Export(graph, noNewGraph, typesToAttributesToSkip);
 }
Exemple #6
0
 /// <summary>
 /// Exports the given graph to a GRS file with the given filename.
 /// Any errors will be reported by exception.
 /// </summary>
 /// <param name="graph">The graph to export. Must be a named graph.</param>
 /// <param name="exportFilename">The filename for the exported file.</param>
 public static void Export(INamedGraph graph, String exportFilename)
 {
     using(GRSExport export = new GRSExport(exportFilename))
         export.Export(graph);
 }
Exemple #7
0
 /// <summary>
 /// Exports the given graph to the file given by the stream writer in grs format.
 /// Any errors will be reported by exception.
 /// </summary>
 /// <param name="graph">The graph to export. Must be a named graph.</param>
 /// <param name="writer">The stream writer to export to.</param>
 public static void Export(INamedGraph graph, StreamWriter writer)
 {
     using(GRSExport export = new GRSExport(writer))
         export.Export(graph);
 }
Exemple #8
0
        /// <summary>
        /// Exports the given named graph to a file with the given filename.
        /// The format is determined by the file extension.
        /// Currently available are: .grs/.grsi or .gxl or .xmi.
        /// Optionally suffixed by .gz; in this case they are saved gzipped.
        /// Any errors will be reported by exception.
        /// </summary>
        /// <param name="graph">The named graph to export.
        /// The .grs/.grsi exporter is exporting the names/including the names; import will return a named graph again.
        /// The .gxl exporter is exporting without the names, which is equivalent of calling the non-named graph export.</param>
        /// The .xmi exporter is using the names as xmi ids.</param>
        /// <param name="filenameParameters">The names of the files to be exported.
        /// The first must be a filename, the following may be used for giving export parameters
        /// (in fact currently no exporter supports multiple files).</param>
        public static void Export(INamedGraph graph, List <String> filenameParameters)
        {
            String       first  = ListGet(filenameParameters, 0);
            StreamWriter writer = null;

            if (first.EndsWith(".gz", StringComparison.InvariantCultureIgnoreCase))
            {
                FileStream filewriter = new FileStream(first, FileMode.OpenOrCreate, FileAccess.Write);
                writer = new StreamWriter(new GZipStream(filewriter, CompressionMode.Compress), System.Text.Encoding.UTF8);
                first  = first.Substring(0, first.Length - 3);
            }
            else
            {
                writer = new StreamWriter(first, false, System.Text.Encoding.UTF8);
            }

            using (writer)
            {
                if (first.EndsWith(".gxl", StringComparison.InvariantCultureIgnoreCase))
                {
                    GXLExport.Export(graph, writer);
                }
                else if (first.EndsWith(".grs", StringComparison.InvariantCultureIgnoreCase) ||
                         first.EndsWith(".grsi", StringComparison.InvariantCultureIgnoreCase))
                {
                    bool noNewGraph = false;
                    Dictionary <String, Dictionary <String, String> > typesToAttributesToSkip = new Dictionary <string, Dictionary <string, string> >();
                    for (int i = 1; i < filenameParameters.Count; ++i)
                    {
                        if (filenameParameters[i].StartsWith("skip/") || filenameParameters[i].StartsWith("skip\\"))
                        {
                            String toSkip    = filenameParameters[i].Substring(5);
                            String type      = toSkip.Substring(0, toSkip.IndexOf('.'));
                            String attribute = toSkip.Substring(toSkip.IndexOf('.') + 1);
                            Dictionary <String, String> attributesToSkip;
                            if (!typesToAttributesToSkip.TryGetValue(type, out attributesToSkip))
                            {
                                typesToAttributesToSkip[type] = new Dictionary <string, string>();
                            }
                            typesToAttributesToSkip[type].Add(attribute, null);
                        }
                        else if (filenameParameters[i] == "nonewgraph")
                        {
                            noNewGraph = true;
                        }
                        else
                        {
                            throw new NotSupportedException("Export Parameter " + i + " not supported: " + filenameParameters[i]);
                        }
                    }
                    GRSExport.Export(graph, writer, noNewGraph, typesToAttributesToSkip.Count > 0 ? typesToAttributesToSkip : null);
                }
                else if (first.EndsWith(".xmi", StringComparison.InvariantCultureIgnoreCase))
                {
                    XMIExport.Export(graph, writer);
                }
                else if (first.EndsWith(".grg", StringComparison.InvariantCultureIgnoreCase))
                {
                    GRGExport.Export(graph, writer);
                }
                else
                {
                    throw new NotSupportedException("File format not supported");
                }
            }
        }