예제 #1
0
        public void GenerateVoidNQuads(string targetFileName)
        {
            var targetDir = Path.GetDirectoryName(targetFileName);

            if (!Directory.Exists(targetDir))
            {
                Directory.CreateDirectory(targetDir);
            }

            var rootTripleCollection = _quinceStore.GetTriplesForSubject(_graph.CreateUriNode(_repositoryUri)).ToList();

            foreach (var subsetTriple in rootTripleCollection.WithPredicate(_voidSubset).ToList())
            {
                rootTripleCollection.AddRange(_quinceStore.GetTriplesForSubject(subsetTriple.Object).Where(t => !rootTripleCollection.Contains(t)));
            }
            foreach (var publisherTriple in rootTripleCollection.WithPredicate(_dctermsPublisher).ToList())
            {
                rootTripleCollection.AddRange(_quinceStore.GetTriplesForSubject(publisherTriple.Object).Where(t => !rootTripleCollection.Contains(t)));
            }
            var formatter = new NQuads11Formatter();

            using (var output = File.Open(targetFileName, FileMode.Create, FileAccess.Write))
            {
                using (var writer = new StreamWriter(output))
                {
                    foreach (var t in rootTripleCollection)
                    {
                        writer.WriteLine("{0} {1} {2} {3} .",
                                         formatter.Format(t.Subject), formatter.Format(t.Predicate), formatter.Format(t.Object), formatter.FormatUri(t.GraphUri));
                    }
                }
            }
        }
예제 #2
0
        private static string GetGraphTriples(IEnumerable <Triple> triples)
        {
            var lineFormat = new NQuads11Formatter();
            var str        = new StringBuilder();

            foreach (var graphGroup in triples.GroupBy(t => t.GraphUri))
            {
                str.Append("GRAPH <");
                str.Append(graphGroup.Key);
                str.AppendLine("> {");
                foreach (var t in graphGroup)
                {
                    str.Append("  ");
                    str.Append(lineFormat.Format(t.Subject));
                    str.Append(" ");
                    str.Append(lineFormat.Format(t.Predicate));
                    str.Append(" ");
                    str.Append(lineFormat.Format(t.Object));
                    str.AppendLine(" .");
                }
                str.AppendLine("}");
            }
            return(str.ToString());
        }