Exemplo n.º 1
0
        private static Uri getValue(string sparql, bool canCreateNewId, Logger logger)
        {
            IGraph graph = GraphRetrieval.GetGraph(sparql, logger, "true");

            if (graph.IsEmpty)
            {
                if (canCreateNewId == true)
                {
                    string id = new IdGenerator.IdMaker().MakeId(logger);
                    logger.Verbose($"Created new id ({id})");
                    return(new Uri(id));
                }
                else
                {
                    logger.Verbose("Not found");
                    return(null);
                }
            }
            else
            {
                Uri result = ((IUriNode)graph.Triples.SubjectNodes.SingleOrDefault()).Uri;
                logger.Verbose($"Found existing ({result})");
                return(result);
            }
        }
Exemplo n.º 2
0
        private IGraph getExistingGraph(Uri subject, Dictionary <string, INode> graphRetrievalDictionary, T settings)
        {
            graphRetrievalDictionary = graphRetrievalDictionary ?? new Dictionary <string, INode>();
            graphRetrievalDictionary.Add("subject", SparqlConstructor.GetNode(subject));
            SparqlConstructor sparqlConstructor = new SparqlConstructor(settings.ExistingGraphSparqlCommand, graphRetrievalDictionary);

            sparqlConstructor.Sparql.Namespaces.AddNamespace("parl", new Uri(schemaNamespace));
            logger.Verbose("Trying to get existing graph");
            return(GraphRetrieval.GetGraph(sparqlConstructor.Sparql.ToString(), logger));
        }
Exemplo n.º 3
0
        public static Dictionary <string, string> GetSubjectsDictionary(string predicate, Logger logger)
        {
            string command = @"
                construct{
                    ?s @predicate ?objectValue.
                }
                where{
                    ?s @predicate ?objectValue.
                }";
            SparqlParameterizedString sparql = new SparqlParameterizedString(command);

            sparql.SetUri("predicate", new Uri($"{schemaNamespace}{predicate}"));
            Dictionary <string, string> result = new Dictionary <string, string>();
            IGraph graph = GraphRetrieval.GetGraph(sparql.ToString(), logger, "false");

            foreach (Triple triple in graph.Triples)
            {
                result.Add(triple.Object.ToString(), triple.Subject.ToString());
            }
            return(result);
        }