Ejemplo n.º 1
0
        private async Task RunNegativeRdfTest(CsvwTestDescription test)
        {
            var actual        = new Graph();
            var insertHandler = new GraphHandler(actual);
            var errorMessages = new List <string>();

            // Set up converter
            var converter = new Converter(
                insertHandler,
                new DefaultResolver(),
                test.Options.Minimal ? ConverterMode.Minimal : ConverterMode.Standard,
                errorMessage => errorMessages.Add(errorMessage),
                suppressStringDatatype: true);

            if (test.Options.Metadata != null)
            {
                var localMetadata = File.ReadAllText(test.Options.Metadata.LocalPath);
                await converter.ConvertWithLocalMetadata(new Uri(_baseUri, test.Action.Uri), new HttpClient(), localMetadata);
            }
            else
            {
                await converter.ConvertAsync(new Uri(_baseUri, test.Action.Uri), new HttpClient());
            }

            Assert.NotEmpty(errorMessages);
        }
Ejemplo n.º 2
0
 public static void Load(this IRdfReader parser, GraphHandler handler, string filename)
 {
     using (var inputStream = new StreamReader(filename))
     {
         parser.Load(handler, inputStream);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// This method fixes the chromosome - there could be cycles before => this method removes the cycles
        /// using graph.
        /// </summary>
        public void FixChromosome()
        {
            if (Fitness != null)
            {
                return;
            }

            var graphHandler = new GraphHandler();

            // in order to fix the chromosome we need to create graph and remove cycles from it
            // cycles are removed by rotating edges of the cycle until there is no cycle
            var graph = graphHandler.CreateGraph(this);

            graphHandler.BreakCycles(graph);

            // update the chromosome => get topologically sorted graph and rewrite values in machine indices
            var topologicalOrder   = graphHandler.GetTopologicalOrder(graph);
            var machineIndices     = new int[JobShop.MachinesCount];
            var machineChromosomes = GetGenes().Select(x => x.Value).Cast <MachineChromosome>().ToList();

            foreach (var operation in topologicalOrder.Where(x => x.Id > int.MinValue && x.Id < int.MaxValue))
            {
                int     machineId             = operation.MachineId;
                ref int machineOperationIndex = ref machineIndices[machineId];

                machineChromosomes[machineId].ReplaceGene(machineOperationIndex, new Gene(operation));
                machineOperationIndex++;
            }
Ejemplo n.º 4
0
        public async Task <JsonResult> getData(string json = null)
        {
            Error.TraceStart();
            string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
            //Error.TraceLog("GraphController.getData, point1");



            StreamReader stream = new StreamReader(Request.InputStream);

            if (json == null)
            {
                json = stream.ReadToEnd();
            }
            if (json != "")
            {
                object      data        = new object();
                DataRequest dataRequest = new JavaScriptSerializer().Deserialize <DataRequest>(json);
                Error.TraceLog("GraphController.getData, point1");
                try
                {
                    GraphHandler GH = new GraphHandler();

                    DataRequest dataResponse = await GH.proceedSQLquery(dataRequest, config);

                    Error.TraceLog("GraphController.getData, point2");
                    if ((dataRequest.beginTime + dataRequest.timeAxisLength) <= AlarmHelper.DateTimeTopkTime(DateTime.Now))
                    {
                        if (dataResponse.tags.All(p => p.vals.All(q => (q == double.MaxValue)) == true))
                        {
                            for (int i = 0; i < dataResponse.tags.Count; i++)
                            {
                                dataResponse.tags[i].vals = null;
                            }
                        }
                    }
                    data = dataResponse;
                    Error.TraceLog("GraphController.getData, point3");
                    return(Json(data, "application/json", JsonRequestBehavior.AllowGet));
                }
                catch (Exception e)
                {
                    data = dataRequest;
                    string k    = e.Message.ToString() + e.Source.ToString() + e.StackTrace.ToString();
                    string name = this.ControllerContext.RouteData.Values["controller"].ToString();
                    Error.toFile(k, name);
                    Session["tempforview"] = Error.timestamp + "   Error " + MvcApplication.ErrorId.ToString() + " occured so please try it again after some time"; //To screen also with id
                    return(Json(data, "application/json", JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 5
0
        private static IGraph executeGraphQuery(string sparql, string infer)
        {
            IGraph result = new Graph();

            using (GraphDBConnector connector = new GraphDBConnector($"infer={infer}"))
            {
                connector.Timeout = 180 * 1000;
                GraphHandler rdfHandler = new GraphHandler(result);
                connector.Query(rdfHandler, null, sparql);
            }
            return(result);
        }
    private static IGraph Load(string source)
    {
        var result           = new Graph();
        var graphHandler     = new GraphHandler(result);
        var strippingHandler = new StripStringHandler(graphHandler);
        var parser           = new TurtleParser();

        using (var reader = new StringReader(source))
        {
            parser.Load(strippingHandler, reader);
        }

        return(result);
    }
Ejemplo n.º 7
0
        public Home(FileStoreManager fileStore, IController controller)
        {
            _fileStore  = fileStore;
            _controller = controller;
            InitializeComponent();

            _highlightedMonth = DateTime.Today;
            _plotter          = new GraphHandler(monthPlot, controller);

            viewer.Controller = controller;

            _toolTipHandler = new ToolTipHandler();

            controller.AddView(this);
        }
        private void TestGraphHandler(ISparqlQueryProcessor processor, String query)
        {
            SparqlQuery q = this._parser.ParseFromString(query);

            Graph expected = processor.ProcessQuery(q) as Graph;

            Assert.NotNull(expected);

            Graph        actual  = new Graph();
            GraphHandler handler = new GraphHandler(actual);

            processor.ProcessQuery(handler, null, q);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 9
0
        private void NavigateLudkoncentration()
        {
            ResetMange();

            LudkoncentrationVisibility = Visibility.Visible;
            OnPropertyChanged(nameof(LudkoncentrationVisibility));

            GraphHandler g = new GraphHandler();

            Graf    = g.DrawLudKoncentration(0);
            GrafTwo = null;

            GraphHolder = "LK";

            SorteringsValg = "Alle";
        }
Ejemplo n.º 10
0
        private void NavigateVægt()
        {
            ResetMange();

            VægtVisibility = Visibility.Visible;
            OnPropertyChanged(nameof(VægtVisibility));

            GraphHandler g = new GraphHandler();

            Graf    = g.DrawVægt(0, "30L");
            GrafTwo = g.DrawVægt(0, "25L");

            GraphHolder = "VA";

            SorteringsValg = "Alle";
        }
Ejemplo n.º 11
0
        private void NavigateMs()
        {
            ResetMange();

            MsVisiblity = Visibility.Visible;
            OnPropertyChanged(nameof(MsVisiblity));

            GraphHandler g = new GraphHandler();

            Graf    = g.DrawMs(0);
            GrafTwo = null;

            GraphHolder = "MS";

            SorteringsValg = "Alle";
        }
Ejemplo n.º 12
0
        public void ParsingRdfXmlStreamingDoesNotExhaustMemory()
        {
            IGraph         g            = new Graph();
            GraphHandler   graphHandler = new GraphHandler(g);
            PagingHandler  paging       = new PagingHandler(graphHandler, 1000);
            CountHandler   counter      = new CountHandler();
            ChainedHandler handler      = new ChainedHandler(new IRdfHandler[] { paging, counter });

            GZippedRdfXmlParser parser = new GZippedRdfXmlParser(RdfXmlParserMode.Streaming);

            parser.Load(handler, @"resources\oom.rdf.gz");

            Assert.False(g.IsEmpty);
            Assert.Equal(1000, counter.Count);
            // Note that the source produces some duplicate triples so triples in the graph will be at most 1000
            Assert.True(g.Triples.Count <= 1000);
        }
        private double Evaluate(ScheduleChromosome chromosome)
        {
            if (chromosome.Fitness != null)
            {
                return(chromosome.Fitness.Value);
            }

            // create graph
            chromosome.FixChromosome();
            var graph = chromosome.Graph;

            double scheduleLength = new GraphHandler().GetMaximumCost(graph, chromosome.TopologicalOrder);

            chromosome.ScheduleLength = scheduleLength;
            chromosome.Fitness        = 1 / (scheduleLength + 1);

            return(chromosome.Fitness.Value);
        }
        private void TestGraphHandler(ISparqlQueryProcessor processor, String query)
        {
            SparqlQuery q = this._parser.ParseFromString(query);

            Graph expected = processor.ProcessQuery(q) as Graph;

            if (expected == null)
            {
                Assert.Fail("Query failed to return a Grah as expected");
            }

            Graph        actual  = new Graph();
            GraphHandler handler = new GraphHandler(actual);

            processor.ProcessQuery(handler, null, q);

            Assert.AreEqual(expected, actual, "Graphs should be equal");
        }
Ejemplo n.º 15
0
        private async Task RunToRdfTest(CsvwTestDescription test, bool expectWarnings)
        {
            var expect = new Graph();

            expect.LoadFromUri(new Uri(_baseUri, test.Result.Uri));

            var actual        = new Graph();
            var insertHandler = new GraphHandler(actual);
            var errorMessages = new List <string>();

            // Set up converter
            var converter = new Converter(
                insertHandler,
                new DefaultResolver(),
                test.Options.Minimal ? ConverterMode.Minimal : ConverterMode.Standard,
                errorMessage => errorMessages.Add(errorMessage),
                suppressStringDatatype: true);

            if (test.Options.Metadata != null)
            {
                var localMetadata = File.ReadAllText(test.Options.Metadata.LocalPath);
                await converter.ConvertWithLocalMetadata(new Uri(_baseUri, test.Action.Uri), new HttpClient(), localMetadata);
            }
            else
            {
                await converter.ConvertAsync(new Uri(_baseUri, test.Action.Uri), new HttpClient());
            }

            //var tableGroup = new TableGroup();
            //var table = new Table(tableGroup) {Url = new Uri(_baseUri, test.Action.Uri)};
            //await converter.ConvertAsync(tableGroup, new DefaultResolver());
            converter.Errors.Should().BeEmpty("expected no errors during conversion");
            var differ = new GraphDiff();

            NormalizeLiterals(expect);
            NormalizeLiterals(actual);
            var graphDiff = differ.Difference(expect, actual);

            // Assert graphs are equal
            //actual.Triples.Count.Should().Be(expect.Triples.Count,
            //    "Count of triples in output graph should match the count of triples in the expected result graph");
            //Assert.Equal(expect.Triples.Count, actual.Triples.Count);
            Assert.True(graphDiff.AreEqual, "Expected graphs to be the same.\n" + ReportGraphDiff(graphDiff));
        }
Ejemplo n.º 16
0
        /// <inheritdoc />
        public object Query(string sparqlQuery)
        {
            var graph        = new Graph();
            var graphHandler = new GraphHandler(graph);

            var resultSet        = new SparqlResultSet();
            var resultSetHandler = new ResultSetHandler(resultSet);

            Query(graphHandler, resultSetHandler, sparqlQuery);

            if (resultSet.ResultsType != SparqlResultsType.Unknown)
            {
                return(resultSet);
            }
            else
            {
                return(graph);
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Pushes the current in-scope Graph onto the Graph stack and creates a new empty Graph to be the in-scope Graph.
        /// </summary>
        /// <remarks>
        /// Used for Graph Literal parsing - Base Uri and Namespace Maps of the outermost Graph is propogated to the innermost Graph.
        /// </remarks>
        public void PushGraph()
        {
            Graph h = new Graph();

            h.NamespaceMap.Import(Namespaces);
            h.BaseUri = BaseUri;

            _handlers.Push(_handler);
            _handler = new GraphHandler(h);
            _handler.StartRdf();

            _subgraphs.Push(_g);
            _g = h;

            VariableContext v = new VariableContext(VariableContextType.None);

            _varContexts.Push(_varContext);
            _varContext = v;
        }
Ejemplo n.º 18
0
        public void SetUp()
        {
            jobShop    = new JobShopLoader().Load("TestExamples/test1.in", false);
            chromosome = new ScheduleChromosome(jobShop);

            var machineChromosome1 = new MachineChromosome(new int[]
            {
                4, 5, 0, 2
            }.Select(x => jobShop.Operations[x]).ToArray());

            chromosome.ReplaceGene(0, new Gene(machineChromosome1));

            var machineChromosome2 = new MachineChromosome(new int[]
            {
                1, 3
            }.Select(x => jobShop.Operations[x]).ToArray());

            chromosome.ReplaceGene(1, new Gene(machineChromosome2));

            graphHandler = new GraphHandler();
        }
Ejemplo n.º 19
0
        public async void TestValidConversions(string tableMetadataPath, string csvFilePath,
                                               string expectedOutputGraphPath)
        {
            var metadataParser =
                new JsonMetadataParser(new DefaultResolver(), new Uri("http://example.org/metadata.json"));

            tableMetadataPath       = Path.Combine("data", tableMetadataPath);
            csvFilePath             = Path.Combine("data", csvFilePath);
            expectedOutputGraphPath = Path.Combine("data", expectedOutputGraphPath);
            TableGroup tableGroup;

            using (var metadataReader = File.OpenText(tableMetadataPath))
            {
                tableGroup = metadataParser.Parse(metadataReader);
            }

            tableGroup.Should().NotBeNull();
            tableGroup.Tables.Should().HaveCount(1);
            var tableMeta = tableGroup.Tables[0];

            tableMeta.Should().NotBeNull(because: "The metadata file should parse as table metadata");
            var outputGraph  = new Graph();
            var graphHandler = new GraphHandler(outputGraph);
            var resolverMock = new Mock <ITableResolver>();

            resolverMock.Setup(x => x.ResolveAsync(It.IsAny <Uri>())).Returns(Task.FromResult(File.OpenRead(csvFilePath) as Stream));
            var converter = new Converter(graphHandler, resolverMock.Object, ConverterMode.Minimal);
            await converter.ConvertAsync(tableMeta.Parent as TableGroup);

            converter.Errors.Count.Should().Be(0, "Expected 0 errors. Got {0}. Error listing is:\n{1}", converter.Errors.Count, string.Join("\n", converter.Errors));
            var turtleParser = new TurtleParser(TurtleSyntax.W3C);
            var expectGraph  = new Graph();

            turtleParser.Load(expectGraph, expectedOutputGraphPath);

            var diff       = new GraphDiff();
            var diffReport = diff.Difference(expectGraph, outputGraph);

            diffReport.AreEqual.Should().BeTrue("Graphs differ");
        }
Ejemplo n.º 20
0
        private async Task <Graph> GenerateDatasetGraphAsync(string csvPath, JObject metadataJson, Uri metadataUri)
        {
            var parser     = new JsonMetadataParser(null, metadataUri);
            var tableGroup = new TableGroup();

            try
            {
                var tableMeta = parser.ParseTable(tableGroup, metadataJson);
                if (tableMeta == null)
                {
                    throw new WorkerException("CSV Conversion failed. Unable to read CSV table metadata.");
                }
            }
            catch (MetadataParseException ex)
            {
                Log.Error(ex, "Invalid CSV table metadata: " + ex.Message);
                throw new WorkerException(ex, "CSV conversion failed. Invalid CSV table metadata: " + ex.Message);
            }

            var graph = new Graph();

            ProgressLog.Info("Running CSV to RDF conversion");
            var graphHandler  = new GraphHandler(graph);
            var tableResolver = new LocalTableResolver(tableGroup.Tables[0].Url, csvPath);
            var converter     = new Converter(graphHandler, tableResolver, ConverterMode.Minimal, (msg) => ProgressLog.Error(msg), this, reportInterval: CsvConversionReportInterval);
            await converter.ConvertAsync(tableGroup);

            if (converter.Errors.Any())
            {
                foreach (var e in converter.Errors)
                {
                    ProgressLog.Error(e);
                }
                throw new WorkerException("One or more errors where encountered during the CSV to RDF conversion.");
            }
            return(graph);
        }
Ejemplo n.º 21
0
 public FindPathCommand(Func <DesiredPathData> desiredPathDataFunc, Action <PathfindingResult> finalAction, GraphHandler graphHandler)
 {
     getDesiredPathData = desiredPathDataFunc;
     this.finalAction   = finalAction;
     this.graphHandler  = graphHandler;
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Runs the task
        /// </summary>
        /// <returns></returns>
        protected override TaskResult RunTaskInternal()
        {
            if (this.Target.IsReadOnly)
            {
                throw new RdfStorageException("Cannot Copy/Move a Graph when the Target is a read-only Store!");
            }

            switch (this.Name)
            {
            case "Rename":
            case "Move":
                //Move/Rename a Graph
                if (ReferenceEquals(this.Source, this.Target) && this.Source.StorageProvider is IUpdateableStorage)
                {
                    //If the Source and Target are identical and it supports SPARQL Update natively then we'll just issue a MOVE command
                    this.Information = "Issuing a MOVE command to rename Graph '" + this._sourceUri.ToSafeString() + "' to '" + this._targetUri.ToSafeString() + "'";
                    SparqlParameterizedString update = new SparqlParameterizedString {
                        CommandText = "MOVE"
                    };
                    if (this._sourceUri == null)
                    {
                        update.CommandText += " DEFAULT TO";
                    }
                    else
                    {
                        update.CommandText += " GRAPH @source TO";
                        update.SetUri("source", this._sourceUri);
                    }
                    if (this._targetUri == null)
                    {
                        update.CommandText += " DEFAULT";
                    }
                    else
                    {
                        update.CommandText += " GRAPH @target";
                        update.SetUri("target", this._targetUri);
                    }
                    ((IUpdateableStorage)this.Source.StorageProvider).Update(update.ToString());
                    this.Information = "MOVE command completed OK, Graph renamed to '" + this._targetUri.ToSafeString() + "'";
                }
                else
                {
                    //Otherwise do a load of the source graph writing through to the target graph
                    IRdfHandler handler;
                    IGraph      g = null;
                    if (this.Target.StorageProvider.UpdateSupported)
                    {
                        //If Target supports update then we'll use a WriteToStoreHandler combined with a GraphUriRewriteHandler
                        handler = new WriteToStoreHandler(this.Target.StorageProvider, this._targetUri);
                        handler = new GraphUriRewriteHandler(handler, this._targetUri);
                    }
                    else
                    {
                        //Otherwise we'll use a GraphHandler and do a save at the end
                        g       = new Graph();
                        handler = new GraphHandler(g);
                    }
                    handler         = new CopyMoveProgressHandler(handler, this, "Moving", this.Target.StorageProvider.UpdateSupported);
                    this._canceller = new CancellableHandler(handler);
                    if (this.HasBeenCancelled)
                    {
                        this._canceller.Cancel();
                    }

                    //Now start reading out the data
                    this.Information = "Copying data from Graph '" + this._sourceUri.ToSafeString() + "' to '" + this._targetUri.ToSafeString() + "'";
                    this.Source.StorageProvider.LoadGraph(this._canceller, this._sourceUri);

                    //If we weren't moving the data directly need to save the resulting graph now
                    if (g != null)
                    {
                        this.Information = "Saving copied data to Target Store...";
                        this.Target.StorageProvider.SaveGraph(g);
                    }

                    //And finally since we've done a copy (not a move) so far we need to delete the original graph
                    //to effect a rename
                    if (this.Source.StorageProvider.DeleteSupported)
                    {
                        this.Information = "Removing source graph to complete the move operation";
                        this.Source.StorageProvider.DeleteGraph(this._sourceUri);

                        this.Information = "Move completed OK, Graph moved to '" + this._targetUri.ToSafeString() + "'" + (ReferenceEquals(this.Source, this.Target) ? String.Empty : " on " + this.Target);
                    }
                    else
                    {
                        this.Information = "Copy completed OK, Graph copied to '" + this._targetUri.ToSafeString() + "'" + (ReferenceEquals(this.Source, this.Target) ? String.Empty : " on " + this.Target) + ".  Please note that as the Source Triple Store does not support deleting Graphs so the Graph remains present in the Source Store";
                    }
                }

                break;

            case "Copy":
                if (ReferenceEquals(this.Source, this.Target) && this.Source.StorageProvider is IUpdateableStorage)
                {
                    //If the Source and Target are identical and it supports SPARQL Update natively then we'll just issue a COPY command
                    this.Information = "Issuing a COPY command to copy Graph '" + this._sourceUri.ToSafeString() + "' to '" + this._targetUri.ToSafeString() + "'";
                    SparqlParameterizedString update = new SparqlParameterizedString();
                    update.CommandText = "COPY";
                    if (this._sourceUri == null)
                    {
                        update.CommandText += " DEFAULT TO";
                    }
                    else
                    {
                        update.CommandText += " GRAPH @source TO";
                        update.SetUri("source", this._sourceUri);
                    }
                    if (this._targetUri == null)
                    {
                        update.CommandText += " DEFAULT";
                    }
                    else
                    {
                        update.CommandText += " GRAPH @target";
                        update.SetUri("target", this._targetUri);
                    }
                    ((IUpdateableStorage)this.Source.StorageProvider).Update(update.ToString());
                    this.Information = "COPY command completed OK, Graph copied to '" + this._targetUri.ToSafeString() + "'";
                }
                else
                {
                    //Otherwise do a load of the source graph writing through to the target graph
                    IRdfHandler handler;
                    IGraph      g = null;
                    if (this.Target.StorageProvider.UpdateSupported)
                    {
                        //If Target supports update then we'll use a WriteToStoreHandler combined with a GraphUriRewriteHandler
                        handler = new WriteToStoreHandler(this.Target.StorageProvider, this._targetUri);
                        handler = new GraphUriRewriteHandler(handler, this._targetUri);
                    }
                    else
                    {
                        //Otherwise we'll use a GraphHandler and do a save at the end
                        g       = new Graph();
                        handler = new GraphHandler(g);
                    }
                    handler         = new CopyMoveProgressHandler(handler, this, "Copying", this.Target.StorageProvider.UpdateSupported);
                    this._canceller = new CancellableHandler(handler);
                    if (this.HasBeenCancelled)
                    {
                        this._canceller.Cancel();
                    }

                    //Now start reading out the data
                    this.Information = "Copying data from Graph '" + this._sourceUri.ToSafeString() + "' to '" + this._targetUri.ToSafeString() + "'";
                    this.Source.StorageProvider.LoadGraph(this._canceller, this._sourceUri);

                    //If we weren't moving the data directly need to save the resulting graph now
                    if (g != null)
                    {
                        this.Information = "Saving copied data to Store...";
                        this.Target.StorageProvider.SaveGraph(g);
                    }

                    this.Information = "Copy completed OK, Graph copied to '" + this._targetUri.ToSafeString() + "'" + (ReferenceEquals(this.Source, this.Target) ? String.Empty : " on " + this.Target.ToString());
                }

                break;
            }

            return(new TaskResult(true));
        }