Exemplo n.º 1
0
        public void SaveGraph(VDS.RDF.IGraph g)
        {
            IGraph newGraph;

            if (g.BaseUri == null)
            {
                newGraph = defaultGraph;
            }
            else
            {
                if (!namedGraphs.TryGetValue(g.BaseUri, out newGraph))
                {
                    namedGraphs.Add(g.BaseUri, newGraph = new SGraph("TODO", g.BaseUri));
                }
            }
            Console.WriteLine("added graph");
            newGraph.Clear();

            int ntriples = 0;

            foreach (var triple in g.Triples)
            {
                if (ntriples % 100000 == 0)
                {
                    Console.Write("r{0} ", ntriples++ / 100000);
                }
                newGraph.Assert(new Triple(newGraph.CreateUriNode("<" + triple.Subject.ToString() + ">"),
                                           newGraph.CreateUriNode("<" + triple.Predicate.ToString() + ">"),
                                           triple.Object.NodeType == VDS.RDF.NodeType.Literal
                        ? (INode)newGraph.CreateLiteralNode(triple.Object.ToString())
                        : newGraph.CreateUriNode("<" + triple.Object.ToString() + ">")));
            }
            newGraph.Build();
        }
Exemplo n.º 2
0
        public void LoadGraph(VDS.RDF.IGraph g, string graphUri)
        {
            IGraph getGraph;

            if (string.IsNullOrWhiteSpace(graphUri))
            {
                getGraph = defaultGraph;
            }
            else
            {
                if (!namedGraphs.TryGetValue(g.BaseUri, out getGraph))
                {
                    return;
                }
            }
            Console.WriteLine("getted graph");


            int ntriples = 0;

            foreach (var triple in getGraph.GetTriples())
            {
                if (ntriples % 100000 == 0)
                {
                    Console.Write("w{0} ", ntriples++ / 100000);
                }
                g.Assert(new VDS.RDF.Triple(g.CreateUriNode(((IUriNode)triple.Subject).Uri),
                                            g.CreateUriNode(((IUriNode)triple.Predicate).Uri),
                                            triple.Object.NodeType == NodeType.Literal
                        ? (VDS.RDF.INode)g.CreateLiteralNode(triple.Object.ToString())
                        : g.CreateUriNode(((IUriNode)triple.Object).Uri)));
            }
        }
Exemplo n.º 3
0
        public void SaveToGraph(VDS.RDF.IGraph target, VDS.RDF.IUriNode provCreatingAction)
        {
            createIdentityNode(target, provCreatingAction);
            //Set the type
            target.Assert(IdentityNode, UriNodeExt.RdfType(target), target.CreateUriNode(UriFactory.Create(Properties.Settings.Default.ScheduledService)));
            IdentityNode.IdentifyNode(target.CreateLiteralNode(TrainUID));
            IUriNode serviceNodePredicate = target.CreateUriNode(Properties.Settings.Default.serviceNodePredicate);

            //TODO: most of the save to graph!
            foreach (ServiceNodeBase node in ServiceNodes)
            {
                //Note that order is crucail here: parent must be set before you try to save to graph and serviceAsNode will be null and afterwards
                //This feels some what fragile and probably needs a good look taking at it
                node.Parent = this;

                node.SaveToGraph(target, provCreatingAction);
                target.Assert(IdentityNode, serviceNodePredicate, node.ServiceAsNode);
            }
        }
Exemplo n.º 4
0
        public virtual void SaveToGraph(VDS.RDF.IGraph target, VDS.RDF.IUriNode provCreatingAction)
        {
            createLocationNode(target);
            //assert that it is a location
            target.Assert(locationNode, UriNodeExt.RdfType(target), target.CreateUriNode(Properties.Settings.Default.Location));
            //assert that it is a tiploc location
            target.Assert(locationNode, UriNodeExt.RdfType(target), target.CreateUriNode(Properties.Settings.Default.TiplocLocation));
            //link to the tiploc code
            ILiteralNode tiplockCodeNode = target.CreateLiteralNode(Tiploc);
            IUriNode     tiplockUriNode  = target.CreateUriNode(Properties.Settings.Default.tiplocCode);

            target.Assert(locationNode, tiplockUriNode, tiplockCodeNode);
            //set the id
            locationNode.IdentifyNode(tiplockCodeNode);
            //lastly, do the prov
            if (provCreatingAction != null)
            {
                locationNode.AssertResponibility(provCreatingAction);
            }
        }
Exemplo n.º 5
0
        public void ProcessHeader(System.IO.StreamReader inStream, ref VDS.RDF.IGraph targetGraph, VDS.RDF.IUriNode generationActivity, string fileName)
        {
            string firstLine = inStream.ReadLine();

            if (!firstLine.StartsWith("HD"))//header record type is HD
            {
                throw new ImportFileFormatException(fileName,
                                                    "File must include a header, denoted HD",
                                                    0,
                                                    0
                                                    );
            }
            string   mainframe_id  = firstLine.Substring(2, 20);
            DateTime date_extract  = DateTime.ParseExact(firstLine.Substring(22, 10), dtFormat, ProgramState.Provider);
            string   curr_file_ref = firstLine.Substring(32, 7);
            string   last_file_ref = firstLine.Substring(39, 7);
            // char update_type = firstLine[46];//not going to use this
            DateTime extract_start = DateTime.ParseExact(firstLine.Substring(48, 6), dateFormat, ProgramState.Provider);
            DateTime extract_end   = DateTime.ParseExact(firstLine.Substring(54, 6), dateFormat, ProgramState.Provider);

            //Now put that in the graph
            string   sourceFileUri  = Common.ImportFileUriBaseString + "#" + DateTime.Now.ToString("o") + "SourceFile_" + fileName;
            IUriNode sourceFileNode = targetGraph.CreateUriNode(UriFactory.Create(sourceFileUri));

            targetGraph.Assert(sourceFileNode, UriNodeExt.RdfType(targetGraph), targetGraph.CreateUriNode("prov:Entity"));
            if (generationActivity != null)
            {
                targetGraph.Assert(generationActivity, targetGraph.CreateUriNode(Properties.Settings.Default.provUsed), sourceFileNode);
            }
            ILiteralNode sourceID = targetGraph.CreateLiteralNode(mainframe_id);

            sourceFileNode.IdentifyNode(sourceID);
            //IUriNode idNode = targetGraph.CreateUriNode(Properties.Settings.Default.ID);
            //targetGraph.Assert(sourceFileNode, idNode, sourceID);
            targetGraph.Assert(sourceFileNode, targetGraph.CreateUriNode(UriFactory.Create(Properties.Settings.Default.provGeneratedTime)),
                               targetGraph.CreateLiteralNode(date_extract.ToString(XmlSpecsHelper.XmlSchemaDateTimeFormat), UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeDateTime)));
            IUriNode     invalidatedNote = targetGraph.CreateUriNode(Properties.Settings.Default.provInvalidAtTime);
            ILiteralNode timeInvalid     = targetGraph.CreateLiteralNode(extract_end.ToString(XmlSpecsHelper.XmlSchemaDateTimeFormat), UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeDateTime));

            targetGraph.Assert(sourceFileNode, invalidatedNote, timeInvalid);
        }
Exemplo n.º 6
0
 protected void createLocationNode(VDS.RDF.IGraph target)
 {
     //Tiploc related information
     locationNode = target.CreateUriNode(GenerateTIPLOCUri(Tiploc));
 }
Exemplo n.º 7
0
        public override void SaveToGraph(VDS.RDF.IGraph target, VDS.RDF.IUriNode provCreatingAction)
        {
            /*DO NOT call base.SaveToGraph at this juncture
             * It will save it as if it's a tiploc
             * and it's not, it merely has one as a location
             * */
            //Create the identifying node for this service
            thisServiceNode = createSerivceNode(target /*,provCreatingAction*/);
            //set the location
            base.createLocationNode(target);
            IUriNode locationLink = target.CreateUriNode(Properties.Settings.Default.locationPredicate);

            target.Assert(thisServiceNode, locationLink, locationNode);
            //save the calling point number
            IUriNode     order            = target.CreateUriNode(Properties.Settings.Default.NodeOrder);
            ILiteralNode callingPointNode = CallNumber.ToLiteral(target);

            target.Assert(thisServiceNode, order, callingPointNode);

            //platform
            if (!string.IsNullOrWhiteSpace(Platform))
            {
                IUriNode hasaplatform = target.CreateUriNode(Properties.Settings.Default.Platform);
                target.Assert(thisServiceNode, hasaplatform, platform.ToLiteral(target));
            }
            //public arrival
            if (PublicArrival.HasValue)
            {
                IUriNode     haspublicArrivalTime = target.CreateUriNode(Properties.Settings.Default.PublicArrival);
                ILiteralNode pubArrivalTime       = target.CreateLiteralNode(PublicArrival.Value.ToString(XmlSpecsHelper.XmlSchemaTimeFormat), UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeTime));
                target.Assert(thisServiceNode, haspublicArrivalTime, pubArrivalTime);
            }
            //scheduled arrival
            if (ScheduledArrival.HasValue)
            {
                IUriNode     hasArrivalTime = target.CreateUriNode(Properties.Settings.Default.ttArrival);
                ILiteralNode arrivalTime    = target.CreateLiteralNode(ScheduledArrival.Value.ToString(XmlSpecsHelper.XmlSchemaTimeFormat), UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeTime));
                target.Assert(thisServiceNode, hasArrivalTime, arrivalTime);
            }
            //passing time
            if (PassingTime.HasValue)
            {
                IUriNode     hasPassingTime = target.CreateUriNode(Properties.Settings.Default.PassingTime);
                ILiteralNode passingTime    = target.CreateLiteralNode(PassingTime.Value.ToString(XmlSpecsHelper.XmlSchemaTimeFormat), UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeTime));
                target.Assert(thisServiceNode, hasPassingTime, passingTime);
            }
            //Departure Time
            if (ScheduledDep.HasValue)
            {
                IUriNode     hasdeptTime = target.CreateUriNode(Properties.Settings.Default.ttDeparture);
                ILiteralNode deptTime    = target.CreateLiteralNode(ScheduledDep.Value.ToString(XmlSpecsHelper.XmlSchemaTimeFormat), UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeTime));
                target.Assert(thisServiceNode, hasdeptTime, deptTime);
            }
            //Public Depture Time
            if (PublicDep.HasValue)
            {
                IUriNode     hasdeptTime = target.CreateUriNode(Properties.Settings.Default.PublicDeparture);
                ILiteralNode deptTime    = target.CreateLiteralNode(PublicDep.Value.ToString(XmlSpecsHelper.XmlSchemaTimeFormat), UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeTime));
                target.Assert(thisServiceNode, hasdeptTime, deptTime);
            }
            //line
            if (!string.IsNullOrWhiteSpace(Line))
            {
                IUriNode hasaLine = target.CreateUriNode(Properties.Settings.Default.Line);
                target.Assert(thisServiceNode, hasaLine, Line.ToLiteral(target));
            }
            //Path
            if (!string.IsNullOrWhiteSpace(Path))
            {
                IUriNode hasaPath = target.CreateUriNode(Properties.Settings.Default.Path);
                target.Assert(thisServiceNode, hasaPath, Path.ToLiteral(target));
            }
            //Time table fudge factor
            if (Performance.HasValue)
            {
                IUriNode hasaPerformance = target.CreateUriNode(Properties.Settings.Default.Performance);
                target.Assert(thisServiceNode, hasaPerformance, Performance.Value.ToLiteral(target));
            }
            //Engineering Allowance
            if (Engineering.HasValue)
            {
                IUriNode hasaEngineeringAllowance = target.CreateUriNode(Properties.Settings.Default.Engineering);
                target.Assert(thisServiceNode, hasaEngineeringAllowance, Engineering.Value.ToLiteral(target));
            }
        }
Exemplo n.º 8
0
 public void LoadGraph(VDS.RDF.IGraph g, Uri graphUri)
 {
     throw new NotImplementedException();
 }