public static INode ToNode(this EntityId entityId, INodeFactory factory)
        {
            if (entityId is BlankId)
            {
                return factory.CreateBlankNode(entityId.Uri.Authority);
            }

            return factory.CreateUriNode(entityId.Uri);
        }
        public static INode ToNode(this EntityId entityId, INodeFactory factory)
        {
            if (entityId is BlankId)
            {
                return(factory.CreateBlankNode(entityId.Uri.Authority));
            }

            return(factory.CreateUriNode(entityId.Uri));
        }
Esempio n. 3
0
        public static INode AsValueNode(this INodeFactory nodeFactory, object value)
        {
            if (value == null)
            {
                return(null);
            }

            switch (value)
            {
            case Uri uriValue:
                return(nodeFactory.CreateUriNode(uriValue));

            case bool boolValue:
                return(new BooleanNode(null, boolValue));

            case byte byteValue:
                return(new ByteNode(null, byteValue));

            case DateTime dateTimeValue:
                return(new DateTimeNode(null, dateTimeValue));

            case DateTimeOffset dateTimeOffsetValue:
                return(new DateTimeNode(null, dateTimeOffsetValue));

            case decimal decimalValue:
                return(new DecimalNode(null, decimalValue));

            case double doubleValue:
                return(new DoubleNode(null, doubleValue));

            case float floatValue:
                return(new FloatNode(null, floatValue));

            case long longValue:
                return(new LongNode(null, longValue));

            case int intValue:
                return(new LongNode(null, intValue));

            case string stringValue:
                return(new StringNode(null, stringValue, UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeString)));

            case char charValue:
                return(new StringNode(null, charValue.ToString(), UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeString)));

            case TimeSpan timeSpanValue:
                return(new TimeSpanNode(null, timeSpanValue));

            default:
                throw new InvalidOperationException($"Can't convert type {value.GetType()}");
            }
        }
Esempio n. 4
0
 internal static INode TryParseNodeValue(INodeFactory factory, String value)
 {
     try
     {
         if (value.StartsWith("_:"))
         {
             return(factory.CreateBlankNode(value.Substring(2)));
         }
         else if (value.StartsWith("<"))
         {
             return(factory.CreateUriNode(new Uri(UnescapeValue(value.Substring(1, value.Length - 2)))));
         }
         else
         {
             if (value.EndsWith("\""))
             {
                 return(factory.CreateLiteralNode(UnescapeValue(value.Substring(1, value.Length - 2))));
             }
             else if (value.EndsWith(">"))
             {
                 String lit = value.Substring(1, value.LastIndexOf("^^<") - 2);
                 String dt  = value.Substring(lit.Length + 5, value.Length - lit.Length - 6);
                 return(factory.CreateLiteralNode(UnescapeValue(lit), new Uri(UnescapeValue(dt))));
             }
             else
             {
                 String lit  = value.Substring(1, value.LastIndexOf("\"@") - 1);
                 String lang = value.Substring(lit.Length + 3);
                 return(factory.CreateLiteralNode(UnescapeValue(lit), UnescapeValue(lang)));
             }
         }
     }
     catch (Exception ex)
     {
         throw new RdfParseException("Failed to parse the value '" + value + "' into a valid Node: " + ex.Message, ex);
     }
 }
        /// <summary>Converts a RomanticWeb's <see cref="Node"/> into dotNetRDF's <see cref="INode"/>.</summary>
        public static INode UnWrapNode(this Node node, INodeFactory nodeFactory)
        {
            if (node.IsUri)
            {
                return nodeFactory.CreateUriNode(node.Uri);
            }

            if (node.IsLiteral)
            {
                if (node.Language != null)
                {
                    return nodeFactory.CreateLiteralNode(node.Literal, node.Language);
                }

                if (node.DataType != null)
                {
                    return nodeFactory.CreateLiteralNode(node.Literal, node.DataType);
                }

                return nodeFactory.CreateLiteralNode(node.Literal);
            }

            return nodeFactory.CreateBlankNode(node.BlankNode);
        }
Esempio n. 6
0
        /// <summary>Converts a RomanticWeb's <see cref="Node"/> into dotNetRDF's <see cref="VDS.RDF.INode"/>.</summary>
        public static VDS.RDF.INode UnWrapNode(this Model.INode node, INodeFactory nodeFactory)
        {
            if (node.IsUri)
            {
                return(nodeFactory.CreateUriNode(node.Uri));
            }

            if (node.IsLiteral)
            {
                if (node.Language != null)
                {
                    return(nodeFactory.CreateLiteralNode(node.Literal, node.Language));
                }

                if (node.DataType != null)
                {
                    return(nodeFactory.CreateLiteralNode(node.Literal, node.DataType));
                }

                return(nodeFactory.CreateLiteralNode(node.Literal));
            }

            return(nodeFactory.CreateBlankNode(node.BlankNode));
        }
Esempio n. 7
0
        /// <summary>
        /// Copies a Node using another Node Factory
        /// </summary>
        /// <param name="original">Node to copy</param>
        /// <param name="target">Factory to copy into</param>
        /// <returns></returns>
        /// <remarks>
        /// <para>
        /// <strong>Warning:</strong> Copying Blank Nodes may lead to unforseen circumstances since no remapping of IDs between Factories is done
        /// </para>
        /// </remarks>
        public static INode CopyNode(INode original, INodeFactory target)
        {
            if (ReferenceEquals(original.Graph, target)) return original;

            switch (original.NodeType)
            {
                case NodeType.Blank:
                    return target.CreateBlankNode(((IBlankNode)original).InternalID);
                case NodeType.GraphLiteral:
                    return target.CreateGraphLiteralNode(((IGraphLiteralNode)original).SubGraph);
                case NodeType.Literal:
                    ILiteralNode lit = (ILiteralNode)original;
                    if (lit.DataType != null)
                    {
                        return target.CreateLiteralNode(lit.Value, lit.DataType);
                    }
                    else if (!lit.Language.Equals(String.Empty))
                    {
                        return target.CreateLiteralNode(lit.Value, lit.Language);
                    }
                    else
                    {
                        return target.CreateLiteralNode(lit.Value);
                    }
                case NodeType.Uri:
                    return target.CreateUriNode(((IUriNode)original).Uri);
                case NodeType.Variable:
                    return target.CreateVariableNode(((IVariableNode)original).VariableName);
                default:
                    throw new RdfException("Unable to Copy '" + original.GetType().ToString() + "' Nodes between Node Factories");
            }
        }
Esempio n. 8
0
        private static List <Triple> ConvertWeatherData(WeatherDataDto weather, Dictionary <string, WeatherStationDto> stations)
        {
            var triples = new TripleBuilder(nodeFactory.AsBlankNode(weather.NodeId));

            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.Type), nodeFactory.AsValueNode(Constants.Types.WeatherData));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataStation), nodeFactory.AsValueNode(weather.station));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataAlti), nodeFactory.AsValueNode(weather.alti));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataDrct), nodeFactory.AsValueNode(weather.drct));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataDwpc), nodeFactory.AsValueNode(weather.dwpc));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataDwpf), nodeFactory.AsValueNode(weather.dwpf));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataFeelc), nodeFactory.AsValueNode(weather.feelc));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataFeelf), nodeFactory.AsValueNode(weather.feelf));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataGust), nodeFactory.AsValueNode(weather.gust));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataIceAccretion1hr), nodeFactory.AsValueNode(weather.ice_accretion_1hr));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataIceAccretion3hr), nodeFactory.AsValueNode(weather.ice_accretion_3hr));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataIceAccretion6hr), nodeFactory.AsValueNode(weather.ice_accretion_6hr));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataLatitude), nodeFactory.AsValueNode(weather.lat));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataLongitude), nodeFactory.AsValueNode(weather.lon));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataMetar), nodeFactory.AsValueNode(weather.metar));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataMslp), nodeFactory.AsValueNode(weather.mslp));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataP01i), nodeFactory.AsValueNode(weather.p01i));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataPeakWindDrct), nodeFactory.AsValueNode(weather.peak_wind_drct));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataPeakWindGust), nodeFactory.AsValueNode(weather.peak_wind_gust));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataPeakWindTime_hh), nodeFactory.AsValueNode(weather.peak_wind_time_hh));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataPeakWindTime_MM), nodeFactory.AsValueNode(weather.peak_wind_time_MM));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataRelh), nodeFactory.AsValueNode(weather.relh));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataSknt), nodeFactory.AsValueNode(weather.sknt));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataSkyc1), nodeFactory.AsValueNode(weather.skyc1));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataSkyc2), nodeFactory.AsValueNode(weather.skyc2));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataSkyc3), nodeFactory.AsValueNode(weather.skyc3));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataSkyc4), nodeFactory.AsValueNode(weather.skyc4));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataSkyl1), nodeFactory.AsValueNode(weather.skyl1));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataSkyl2), nodeFactory.AsValueNode(weather.skyl2));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataSkyl3), nodeFactory.AsValueNode(weather.skyl3));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataSkyl4), nodeFactory.AsValueNode(weather.skyl4));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataTimestamp), nodeFactory.AsValueNode(weather.valid));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataTmpc), nodeFactory.AsValueNode(weather.tmpc));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataTmpf), nodeFactory.AsValueNode(weather.tmpf));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataVsbyKm), nodeFactory.AsValueNode(weather.vsby_km));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataVsbyMi), nodeFactory.AsValueNode(weather.vsby_mi));
            triples.Add(nodeFactory.CreateUriNode(Constants.Predicates.WeatherDataWxcodes), nodeFactory.AsValueNode(weather.wxcodes));

            if (stations.TryGetValue(weather.station, out WeatherStationDto station))
            {
                triples.Add(nodeFactory.AsUriNode(Constants.Predicates.HasStation), nodeFactory.AsBlankNode(station.NodeId));
            }

            return(triples.Build());
        }
Esempio n. 9
0
 public static INode AsUriNode(this INodeFactory nodeFactory, Uri uri)
 {
     return(nodeFactory.CreateUriNode(uri));
 }
 internal static INode TryParseNodeValue(INodeFactory factory, String value)
 {
     try
     {
         if (value.StartsWith("_:"))
         {
             return factory.CreateBlankNode(value.Substring(2));
         }
         else if (value.StartsWith("<"))
         {
             return factory.CreateUriNode(new Uri(UnescapeValue(value.Substring(1, value.Length - 2))));
         }
         else
         {
             if (value.EndsWith("\""))
             {
                 return factory.CreateLiteralNode(UnescapeValue(value.Substring(1, value.Length - 2)));
             }
             else if (value.EndsWith(">"))
             {
                 String lit = value.Substring(1, value.LastIndexOf("^^<") - 2);
                 String dt = value.Substring(lit.Length + 5, value.Length - lit.Length - 6);
                 return factory.CreateLiteralNode(UnescapeValue(lit), new Uri(UnescapeValue(dt)));
             }
             else
             {
                 String lit = value.Substring(1, value.LastIndexOf("\"@") - 1);
                 String lang = value.Substring(lit.Length + 3);
                 return factory.CreateLiteralNode(UnescapeValue(lit), UnescapeValue(lang));
             }
         }
     }
     catch (Exception ex)
     {
         throw new RdfParseException("Failed to parse the value '" + value + "' into a valid Node: " + ex.Message, ex);
     }
 }
Esempio n. 11
0
        /// <summary>
        /// Gets the Nodes that the algorithm should generate the descriptions for
        /// </summary>
        /// <param name="factory">Factory to create Nodes in</param>
        /// <param name="context">SPARQL Evaluation Context</param>
        /// <returns></returns>
        private List<INode> GetNodes(INodeFactory factory, SparqlEvaluationContext context)
        {
            INamespaceMapper nsmap = (context.Query != null ? context.Query.NamespaceMap : new NamespaceMapper(true));
            Uri baseUri = (context.Query != null ? context.Query.BaseUri : null);

            //Build a list of INodes to describe
            List<INode> nodes = new List<INode>();
            foreach (IToken t in context.Query.DescribeVariables)
            {
                switch (t.TokenType)
                {
                    case Token.QNAME:
                    case Token.URI:
                        //Resolve Uri/QName
                        nodes.Add(factory.CreateUriNode(new Uri(Tools.ResolveUriOrQName(t, nsmap, baseUri))));
                        break;

                    case Token.VARIABLE:
                        //Get Variable Values
                        String var = t.Value.Substring(1);
                        if (context.OutputMultiset.ContainsVariable(var))
                        {
                            foreach (ISet s in context.OutputMultiset.Sets)
                            {
                                INode temp = s[var];
                                if (temp != null) nodes.Add(temp);
                            }
                        }
                        break;

                    default:
                        throw new RdfQueryException("Unexpected Token '" + t.GetType().ToString() + "' in DESCRIBE Variables list");
                }
            }
            return nodes;
        }
Esempio n. 12
0
        /// <summary>
        /// This method is called for every Lambda invocation. This method takes in an S3 event object and can be used
        /// to respond to S3 notifications.
        /// </summary>
        /// <param name="s3Event"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task FunctionHandler(S3Event s3Event, ILambdaContext context)
        {
            foreach (var record in s3Event.Records)
            {
                try
                {
                    using (GetObjectResponse response = await _s3Client.GetObjectAsync(new GetObjectRequest()
                    {
                        BucketName = record.S3.Bucket.Name,
                        Key = record.S3.Object.Key
                    }))
                    {
                        using (StreamReader reader = new StreamReader(response.ResponseStream))
                        {
                            //
                            // get main face
                            //
                            var selfieDetail = JsonConvert.DeserializeObject <SelfieDetail>(await reader.ReadToEndAsync());
                            var mainFace     = selfieDetail.FacesDetails.OrderByDescending(faceDetail => faceDetail.BoundingBox.Width * faceDetail.BoundingBox.Height).First();

                            //
                            // load selfies graph
                            //
                            IGraph selfiesGraph = new Graph();
                            _blazegraph.LoadGraph(selfiesGraph, UriFactory.Create(SELFIES_GRAPH));

                            //
                            // create triples
                            //
                            INode imageNode = null;
                            try
                            {
                                imageNode = _nodeFactory.CreateUriNode(UriFactory.Create(Uri.EscapeUriString("http://blazegraph-webapp/" + selfieDetail.ImageName)));
                            }
                            catch (Exception ex)
                            {
                                context.Logger.LogLine(ex.Message);
                                return;
                            }

                            var triples = new List <Triple>();

                            // image instance is of type Selfie class
                            triples.Add(new Triple(
                                            subj: imageNode,
                                            pred: _nodeFactory.CreateUriNode(UriFactory.Create(NamespaceMapper.RDF + "type")),
                                            obj: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie"))
                                            ));

                            // image instance label
                            triples.Add(new Triple(
                                            subj: imageNode,
                                            pred: _nodeFactory.CreateUriNode(UriFactory.Create(NamespaceMapper.RDFS + "label")),
                                            obj: _nodeFactory.CreateLiteralNode(selfieDetail.ImageName, new Uri(XmlSpecsHelper.XmlSchemaDataTypeString))
                                            ));

                            // image instance has a faceDetail instance
                            triples.Add(new Triple(
                                            subj: imageNode,
                                            pred: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/hasFaceDetail")),
                                            obj: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/faceDetail/" + selfieDetail.ImageName))
                                            ));

                            // faceDetail instance is of type FaceDetail class
                            triples.Add(new Triple(
                                            subj: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/faceDetail/" + selfieDetail.ImageName)),
                                            pred: _nodeFactory.CreateUriNode(UriFactory.Create(NamespaceMapper.RDF + "type")),
                                            obj: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/faceDetail"))
                                            ));

                            // filling faceDetail attributes
                            triples.AddRange(new List <Triple>()
                            {
                                new Triple(
                                    subj: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/faceDetail/" + selfieDetail.ImageName)),
                                    pred: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/faceDetail/isGender")),
                                    obj: _nodeFactory.CreateLiteralNode(mainFace.Gender.Value.ToString().ToLower(), new Uri(XmlSpecsHelper.XmlSchemaDataTypeString))
                                    ),
                                new Triple(
                                    subj: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/faceDetail/" + selfieDetail.ImageName)),
                                    pred: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/faceDetail/hasMinAge")),
                                    obj: _nodeFactory.CreateLiteralNode(mainFace.AgeRange.Low.ToString(), new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger))
                                    ),
                                new Triple(
                                    subj: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/faceDetail/" + selfieDetail.ImageName)),
                                    pred: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/faceDetail/hasMaxAge")),
                                    obj: _nodeFactory.CreateLiteralNode(mainFace.AgeRange.High.ToString(), new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger))
                                    ),
                                new Triple(
                                    subj: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/faceDetail/" + selfieDetail.ImageName)),
                                    pred: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/faceDetail/isSmiling")),
                                    obj: _nodeFactory.CreateLiteralNode(Convert.ToInt32(mainFace.Smile.Value).ToString(), new Uri(XmlSpecsHelper.XmlSchemaDataTypeBoolean))
                                    ),
                                new Triple(
                                    subj: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/faceDetail/" + selfieDetail.ImageName)),
                                    pred: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/faceDetail/hasSunglasses")),
                                    obj: _nodeFactory.CreateLiteralNode(Convert.ToInt32(mainFace.Sunglasses.Value).ToString(), new Uri(XmlSpecsHelper.XmlSchemaDataTypeBoolean))
                                    ),
                                new Triple(
                                    subj: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/faceDetail/" + selfieDetail.ImageName)),
                                    pred: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/faceDetail/isFeeling")),
                                    obj: _nodeFactory.CreateLiteralNode(mainFace.Emotions.OrderByDescending(emotion => emotion.Confidence).First().Type.ToString().ToLower(),
                                                                        new Uri(XmlSpecsHelper.XmlSchemaDataTypeString))
                                    )
                            });

                            // image instance has scene instance
                            triples.Add(new Triple(
                                            subj: imageNode,
                                            pred: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/hasScene")),
                                            obj: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/scene/" + selfieDetail.ImageName))
                                            ));

                            // scene instance is of type Scene class
                            triples.Add(new Triple(
                                            subj: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/scene/" + selfieDetail.ImageName)),
                                            pred: _nodeFactory.CreateUriNode(UriFactory.Create(NamespaceMapper.RDF + "type")),
                                            obj: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/scene"))
                                            ));

                            // filling scence attributes
                            foreach (var label in selfieDetail.Labels)
                            {
                                triples.Add(new Triple(
                                                subj: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/scene/" + selfieDetail.ImageName)),
                                                pred: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/scene/isDescribedBy")),
                                                obj: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/scene/" + label.Name))
                                                ));
                                foreach (var parentLabel in label.Parents)
                                {
                                    triples.Add(new Triple(
                                                    subj: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/scene/" + label.Name)),
                                                    pred: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/scene/hasParent")),
                                                    obj: _nodeFactory.CreateUriNode(UriFactory.Create("http://blazegraph-webapp/selfie/scene/" + parentLabel.Name))
                                                    ));
                                }
                            }

                            //
                            // updated triples in graph
                            //
                            try
                            {
                                _blazegraph.UpdateGraph(UriFactory.Create(SELFIES_GRAPH), triples, new List <Triple>());
                                context.Logger.LogLine("Updated triples successfully.");
                            }
                            catch (Exception ex)
                            {
                                context.Logger.LogLine(ex.Message);
                                context.Logger.LogLine(ex.InnerException.Message);
                                return;
                            }
                        }
                    }
                }
                catch (AmazonS3Exception ex)
                {
                    context.Logger.LogLine(ex.Message);
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Decodes an Object into an appropriate Node
        /// </summary>
        /// <param name="factory">Node Factory to use to create Node</param>
        /// <param name="n">Object to convert</param>
        /// <returns></returns>
        private INode LoadNode(INodeFactory factory, Object n)
        {
            INode temp;
            if (n is SqlExtendedString)
            {
                SqlExtendedString iri = (SqlExtendedString)n;
                if (iri.IriType == SqlExtendedStringType.BNODE)
                {
                    //Blank Node
                    temp = factory.CreateBlankNode(n.ToString().Substring(9));

                }
                else if (iri.IriType != iri.StrType)
                {
                    //Literal
                    temp = factory.CreateLiteralNode(n.ToString());
                }
                else if (iri.IriType == SqlExtendedStringType.IRI)
                {
                    //Uri
                    Uri u = new Uri(n.ToString(), UriKind.RelativeOrAbsolute);
                    if (!u.IsAbsoluteUri)
                    {
                        throw new RdfParseException("Virtuoso returned a URI Node which has a relative URI, unable to resolve the URI for this node");
                    }
                    temp = factory.CreateUriNode(u);
                }
                else
                {
                    //Assume a Literal
                    temp = factory.CreateLiteralNode(n.ToString());
                }
            }
            else if (n is SqlRdfBox)
            {
                SqlRdfBox lit = (SqlRdfBox)n;
                if (lit.StrLang != null)
                {
                    //Language Specified Literal
                    temp = factory.CreateLiteralNode(n.ToString(), lit.StrLang);
                }
                else if (lit.StrType != null)
                {
                    //Data Typed Literal
                    temp = factory.CreateLiteralNode(n.ToString(), new Uri(lit.StrType));
                }
                else
                {
                    //Literal
                    temp = factory.CreateLiteralNode(n.ToString());
                }
            }
            else if (n is String)
            {
                String s = n.ToString();
                if (s.StartsWith("nodeID://"))
                {
                    //Blank Node
                    temp = factory.CreateBlankNode(s.Substring(9));
                }
                else
                {
                    //Literal
                    temp = factory.CreateLiteralNode(s);
                }
            }
            else if (n is Int32)
            {
                temp = ((Int32)n).ToLiteral(factory);
            }
            else if (n is Int16)
            {
                temp = ((Int16)n).ToLiteral(factory);
            }
            else if (n is Single)
            {
                temp = ((Single)n).ToLiteral(factory);
            }
            else if (n is Double)
            {
                temp = ((Double)n).ToLiteral(factory);
            }
            else if (n is Decimal)
            {
                temp = ((Decimal)n).ToLiteral(factory);
            }
            else if (n is DateTime)
            {
                temp = ((DateTime)n).ToLiteral(factory);
            }
            else if (n is TimeSpan)
            {
                temp = ((TimeSpan)n).ToLiteral(factory);
            }
            else if (n is Boolean)
            {
                temp = ((Boolean)n).ToLiteral(factory);
            }
            else if (n is DBNull)
            {
                //Fix by Alexander Sidarov for Virtuoso's results for unbound variables in OPTIONALs
                temp = null;
            }
            else
            {
                throw new RdfStorageException("Unexpected Object Type '" + n.GetType().ToString() + "' returned from SPASQL SELECT query to the Virtuoso Quad Store");
            }
            return temp;
        }