public async Task TestTwitterStorage()
        {
            IDataParser Parser = DataParserFactory.CreateParser("Twitter", "#freebandnames");

            Assert.IsNotNull(Parser);

            Assert.IsInstanceOfType(Parser, typeof(IDataParser), $"{nameof(Parser)} must inherit {nameof(IDataParser)}");
            Assert.IsInstanceOfType(Parser, typeof(DataParserBase), $"{nameof(Parser)} must inherit {nameof(DataParserBase)}");
            Assert.IsInstanceOfType(Parser, typeof(TwitterParser), $"{nameof(Parser)} must be a {nameof(DataParser.DataParsers.TwitterParser)}");

            Assert.IsNotNull(Parser.ProviderName, $"{nameof(Parser.ProviderName)} must have a value assigned (\"Twitter\").");
            Assert.AreEqual(Parser.ProviderName, "Twitter", $"{nameof(Parser.ProviderName)} must have a value (\"Twitter\").");

            Assert.IsNotNull(Parser.SearchTerm, $"{nameof(Parser.SearchTerm)} must have a value assigned (\"#freebandnames\").");
            Assert.AreEqual("#freebandnames", Parser.SearchTerm, $"{Parser.SearchTerm} must have a value (\"#freebandnames\").");

            TwitterParser TwitterParser = (TwitterParser)Parser;

            DataModel Model = TwitterParser.ParseResult(Resources.SampleTwitterJson);

            Assert.IsNotNull(Model, $"{nameof(Model)} must not be null. This indicates that {nameof(TwitterParser.ParseResult)} failed.");

            using (HttpClient Client = new HttpClient())
            {
                string JsonModel = new JavaScriptSerializer().Serialize(Model);
                Assert.IsNotNull(JsonModel, $"{JsonModel} must be a valid JSON string.");

                StringContent       Content         = new StringContent(JsonModel, Encoding.UTF8, "application/json");
                HttpResponseMessage ResponseMessage = await Client.PostAsync("http://localhost:46778/News", Content);

                Assert.IsTrue(ResponseMessage.IsSuccessStatusCode, $"{ResponseMessage.IsSuccessStatusCode} must be true. Otherwise it indicates a failed REST POST request.");
            }
        }
        public TabularDataViewModel(ContentItem model)
            : base(model)
        {
            IDataFormatResolver resolver = new DataFormatResolver();
            List <IParser>      parsers  = new List <IParser>();

            parsers.Add(new Parsing.MongoDB.MongoDBJsonParser());

            IDataParserFactory factory = new DataParserFactory(resolver, parsers);

            _DataParser = new DataParser(factory);
        }
Beispiel #3
0
        public static async Task <LabellingJob> RunCreateJobTest()
        {
            ILabellingJobRepository jobRepo       = new LabellingJobRepositoryFactory().Create();
            IJobIterationRepository iterationRepo = new JobIterationRepositoryFactory().Create();

            IDataParser parser     = new DataParserFactory().Create(DataFormats.CIFAR10);
            IDataFormat dataFormat = parser.Format;
            IDataStore  dataStore  = new DataStoreFactory().CreateOrConnect("TestJack", dataFormat);

            IPredictiveModelFactory modelFactory = new PredictiveModelFactory();
            IPredictiveModel        model        = modelFactory.Create("LinearRegression");

            ISelectionStrategyFactory   ssFactory    = new SelectionStrategyFactory();
            Dictionary <string, string> ssParameters = new Dictionary <string, string>();

            ssParameters.Add("randomSeed", "15");
            ISelectionStrategy selectionStrategy = ssFactory.Create("RandomSelectionStrategy", ssParameters);

            IStoppingCriterionFactory   scFactory    = new StoppingCriterionFactory();
            Dictionary <string, string> scParameters = new Dictionary <string, string>();

            scParameters.Add("maxLabels", "15");
            IStoppingCriterion stoppingCriterion = scFactory.Create("LabelLimit", scParameters);

            ISeedingStrategyFactory     seedingFactory    = new SeedingStrategyFactory();
            Dictionary <string, string> seedingParameters = new Dictionary <string, string>();

            seedingParameters.Add("randomSeed", "15");
            ISeedingStrategy seedingStrategy = seedingFactory.Create("RandomSeedingStrategy", seedingParameters);

            IJobIterationNotifier notifier = new JobIterationNotifierFactory().Create();

            int batchSize = 3;
            int seedSize  = 3;

            var job = await ActiveLoop.CreateLabellingJob(
                jobRepo : jobRepo,
                iterationRepo : iterationRepo,
                dataStore : dataStore,
                model : model,
                selectionStrategy : selectionStrategy,
                stoppingCriterion : stoppingCriterion,
                seedingStrategy : seedingStrategy,
                notifier : notifier,
                dataFormat : dataFormat,
                batchSize : batchSize,
                seedSize : seedSize);

            return(job);
        }
Beispiel #4
0
        /// <summary>
        /// Parsers the files binary content into a abi parser context.
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static IParserContext Parse(BinaryReader reader)
        {
            var rawData = new Ab1Header(reader);
            IVersionedDataParser dataParser = DataParserFactory.GetParser(rawData.MajorVersion);
            var context = new ParserContext
            {
                Header = rawData,
                Reader = reader
            };

            dataParser.ParseData(context);

            return(context);
        }
        public async Task <IHttpActionResult> Post([FromUri] string provider, [FromUri] string searchTerm, HttpRequestMessage json)
        {
            if (string.IsNullOrEmpty(provider))
            {
                return(BadRequest("Provider must be set."));
            }

            if (string.IsNullOrEmpty(searchTerm))
            {
                return(BadRequest("Search term must be set."));
            }

            string JSON = await json.Content.ReadAsStringAsync();

            if (string.IsNullOrEmpty(JSON))
            {
                return(BadRequest("JSON data must be set."));
            }

            try
            {
                JsonSchema Schema     = JsonSchema.Parse(JSON);
                JObject    JsonObject = JObject.Parse(JSON);

                if (!JsonObject.IsValid(Schema))
                {
                    return(BadRequest("JSON provided is invalid."));
                }
            }
            catch (JsonReaderException)
            {
                return(BadRequest("JSON provided is invalid."));
            }

            IDataParser Parser = DataParserFactory.CreateParser(provider, searchTerm);
            DataModel   Model  = Parser.ParseResult(JSON);

            if (Model != null)
            {
                if (await Parser.StoreData(Model))
                {
                    return(Ok("Data sent to storage successfully."));
                }
            }


            return(BadRequest("Data has not been stored."));
        }
Beispiel #6
0
        /// <summary>
        ///     Parsers the files binary content into a abi parser context using
        ///     the specified alphabet.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="alphabet"></param>
        /// <returns></returns>
        public static IParserContext Parse(BinaryReader reader, IAlphabet alphabet)
        {
            // Default to the DNA alphabet
            if (alphabet == null)
            {
                alphabet = Alphabets.DNA;
            }

            var rawData = new Ab1Header(reader);
            IVersionedDataParser dataParser = DataParserFactory.GetParser(rawData.MajorVersion);
            var context = new ParserContext {
                Header = rawData, Reader = reader, Alphabet = alphabet,
            };

            dataParser.ParseData(context);

            return(context);
        }
        public void TestTwitterParser()
        {
            IDataParser Parser = DataParserFactory.CreateParser("Twitter", "#freebandnames");

            Assert.IsNotNull(Parser);

            Assert.IsInstanceOfType(Parser, typeof(IDataParser), $"{nameof(Parser)} must inherit {nameof(IDataParser)}");
            Assert.IsInstanceOfType(Parser, typeof(DataParserBase), $"{nameof(Parser)} must inherit {nameof(DataParserBase)}");
            Assert.IsInstanceOfType(Parser, typeof(TwitterParser), $"{nameof(Parser)} must be a {nameof(DataParsers.TwitterParser)}");

            Assert.IsNotNull(Parser.ProviderName, $"{nameof(Parser.ProviderName)} must have a value assigned (\"Twitter\").");
            Assert.AreEqual(Parser.ProviderName, "Twitter", $"{nameof(Parser.ProviderName)} must have a value (\"Twitter\").");

            Assert.IsNotNull(Parser.SearchTerm, $"{nameof(Parser.SearchTerm)} must have a value assigned (\"#freebandnames\").");
            Assert.AreEqual("#freebandnames", Parser.SearchTerm, $"{Parser.SearchTerm} must have a value (\"#freebandnames\").");

            TwitterParser TwitterParser = (TwitterParser)Parser;

            DataModel Model = TwitterParser.ParseResult(Resources.SampleTwitterJson);

            Assert.IsNotNull(Model, $"{nameof(Model)} must not be null. This indicates that {nameof(TwitterParser.ParseResult)} failed.");

            Assert.IsNotNull(Model.SearchTerm, $"{nameof(Model.SearchTerm)} must have a value assigned (\"#freebandnames\").");
            Assert.AreEqual(Model.SearchTerm, TwitterParser.SearchTerm, $"{nameof(Model.SearchTerm)} and {nameof(TwitterParser.SearchTerm)} must have equal values.");

            Assert.IsNotNull(Model.Message, $"{nameof(Model.Message)} must have a value (\"Aggressive Ponytail #freebandnames\").");
            Assert.AreEqual(Model.Message, "Aggressive Ponytail #freebandnames");

            Assert.IsNotNull(Model.Date, $"{nameof(Model.Date)} must have a value (Mon Sep 24 03:35:21 +0000 2012).");
            Assert.AreEqual(Model.Date,
                            DateTime.ParseExact("Mon Sep 24 03:35:21 +0000 2012", "ddd MMM dd HH:mm:ss +ffff yyyy",
                                                new CultureInfo("en-US")), $"{nameof(Model.Date)} must match the value (Mon Sep 24 03:35:21 +0000 2012).");

            Assert.AreEqual(Model.Provider, TwitterParser.ProviderName, $"{nameof(Model.Provider)} and {nameof(TwitterParser.ProviderName)} must have equal values.");

            Assert.IsNotNull(Model.Poster, $"{nameof(Model.Poster)} must have a value assigned (\"@sean_cummings\")");
            Assert.AreEqual("@sean_cummings", Model.Poster, $"{nameof(Model.Poster)} must have (\"@sean_cummings\") as its value.");
        }
Beispiel #8
0
 public PageRepository(DataParserFactory parserFactory, DirectorySearcher directorySearcher)
 {
     this.parserFactory     = parserFactory;
     this.directorySearcher = directorySearcher;
 }
        static void Main(string[] args)
        {
            #region Simulating the form created event that created FieldMappings
            mapper.AddField("sif_bookTitle",
                            new FieldMapping
            {
                FieldLabel      = "Book Title",
                FieldName       = "sif_bookTitle",
                FieldAPIName    = "Book_Title__c",
                DataParserClass = "TextDataParser"
            });
            mapper.AddField("sif_penName",
                            new FieldMapping
            {
                FieldLabel      = "Pen Name",
                FieldName       = "sif_penName",
                FieldAPIName    = "Pen_Name__c",
                DataParserClass = "TextDataParser"
            });
            mapper.AddField("sif_coverImages",
                            new FieldMapping
            {
                FieldLabel      = "Cover Images",
                FieldName       = "sif_coverImages",
                FieldAPIName    = "",
                DataParserClass = "FileDataParser"
            });
            mapper.AddField("sif_manuscripts",
                            new FieldMapping
            {
                FieldLabel      = "Manuscripts",
                FieldName       = "sif_manuscripts",
                FieldAPIName    = "",
                DataParserClass = "FileDataParser"
            });
            mapper.AddField("sif_characters",
                            new FieldMapping
            {
                FieldLabel      = "Characters",
                FieldName       = "sif_characters",
                FieldAPIName    = "",
                DataParserClass = "DynamicTextDataParser"
            });

            #endregion


            Dictionary <string, dynamic> fieldNameValuePairsToUpdate = new Dictionary <string, dynamic>();
            fieldNameValuePairsToUpdate.Add("sif_bookTitle", "My Book Title Number 2");
            fieldNameValuePairsToUpdate.Add("sif_penName", "My Pen Name");
            fieldNameValuePairsToUpdate.Add("sif_coverImages", new List <Models.File> {
                new Models.File {
                    ID = 12345, Name = "cover1.jpg", Url = "https://something.authorsolutions.com/cover1.jpg"
                },
                new Models.File {
                    ID = 23456, Name = "cover2.jpg", Url = "https://something.authorsolutions.com/cover2.jpg"
                },
                new Models.File {
                    ID = 34567, Name = "cover3.jpg", Url = "https://something.authorsolutions.com/cover3.jpg"
                }
            });
            fieldNameValuePairsToUpdate.Add("sif_characters", new List <DynamicText> {
                new DynamicText {
                    Sequence = 1, Data = "Tom"
                },
                new DynamicText {
                    Sequence = 2, Data = "Jerry"
                }
            });

            #region Simulating Form Save Action
            dynamic formData = JValue.Parse(System.IO.File.ReadAllText("formData.json"));
            foreach (string fieldName in fieldNameValuePairsToUpdate.Keys)
            {
                FieldMapping fieldMapping = mapper.GetFieldMappingBykey(fieldName);
                IDataParser  parser       = DataParserFactory.GetParser(fieldMapping.DataParserClass);
                formData = parser.UpdateData(formData, fieldName, fieldNameValuePairsToUpdate[fieldName]);
            }
            #endregion

            // Save FormDataJSON
            System.IO.File.WriteAllText("formData.json", JsonConvert.SerializeObject(formData, Formatting.Indented));

            #region Retrieve Data for Summary
            Dictionary <string, FormData> fieldNameValuePairsToDisplay = new Dictionary <string, FormData>();
            foreach (var field in formData)
            {
                FieldMapping fieldMapping = mapper.GetFieldMappingBykey(field.Name);
                IDataParser  parser       = DataParserFactory.GetParser(fieldMapping.DataParserClass);
                fieldNameValuePairsToDisplay.Add(fieldMapping.FieldLabel, parser.RetrieveData(formData, field.Name, fieldMapping));
            }
            #endregion

            //Trying to Cast the FormData
            foreach (FormData dataObject in fieldNameValuePairsToDisplay.Values)
            {
                var strongTypedData = CastHelper.Cast(dataObject.Data, dataObject.CastClass);
            }
        }
Beispiel #10
0
 public ModelRepository(DataFileFetcher dataFileFetcher, DataParserFactory parserFactory, ModelTypeFetcher typeFetcher)
 {
     this.dataFileFetcher = dataFileFetcher;
     this.parserFactory   = parserFactory;
     this.typeFetcher     = typeFetcher;
 }
Beispiel #11
0
 public DataParserFactoryTest()
 {
     factory = new DataParserFactory(new SectorElementCollection(), new Mock <IEventLogger>().Object);
 }
        public int Compile()
        {
            events.AddEvent(new ComplilationStartedEvent());

            CompilerArgumentsValidator.Validate(events, arguments);
            if (events.HasFatalError())
            {
                events.AddEvent(new CompilationFinishedEvent(false));
                return(1);
            }

            // Parse all the config files
            OutputGroupRepository outputGroups = new OutputGroupRepository();

            ConfigInclusionRules config;

            try
            {
                events.AddEvent(new CompilationMessage("Loading config files"));
                config = ConfigFileLoaderFactory.Make().LoadConfigFiles(arguments.ConfigFiles, arguments);
            } catch (ConfigFileInvalidException e)
            {
                events.AddEvent(new CompilationMessage(e.Message));
                events.AddEvent(new CompilationFinishedEvent(false));
                return(1);
            }

            // Parse all the input files and create elements
            SectorElementCollection sectorElements = new SectorElementCollection();
            DataParserFactory       parserFactory  = new DataParserFactory(sectorElements, events);
            InputFileList           fileList;

            try
            {
                events.AddEvent(new CompilationMessage("Building input file list"));
                fileList = InputFileListFactory.CreateFromInclusionRules(
                    new SectorDataFileFactory(new InputFileStreamFactory()),
                    config,
                    outputGroups
                    );
            }
            catch (System.Exception exception)
            {
                events.AddEvent(new CompilationMessage(exception.Message));
                events.AddEvent(new CompilationFinishedEvent(false));
                return(1);
            }

            events.AddEvent(new CompilationMessage("Injecting pre-parse static data"));
            RunwayCentrelineInjector.InjectRunwayCentrelineData(sectorElements);

            events.AddEvent(new CompilationMessage("Parsing input files"));
            foreach (AbstractSectorDataFile dataFile in fileList)
            {
                parserFactory.GetParserForFile(dataFile).ParseData(dataFile);
            }

            if (events.HasFatalError())
            {
                events.AddEvent(new CompilationFinishedEvent(false));
                return(1);
            }

            // There's some static data we need to inject to the collection for adjacent airports...
            events.AddEvent(new CompilationMessage("Injecting post-parse static data"));
            AdjacentAirportsInjector.InjectAdjacentAirportsData(sectorElements);


            // Now all the data is loaded, validate that there are no broken references etc.
            if (arguments.ValidateOutput)
            {
                events.AddEvent(new CompilationMessage("Validating data"));
                OutputValidator.Validate(sectorElements, arguments, events);
                if (events.HasFatalError())
                {
                    events.AddEvent(new CompilationFinishedEvent(false));
                    return(1);
                }
            }
            else
            {
                events.AddEvent(new CompilationMessage("Skipping output validation"));
            }

            // Generate the output
            OutputGenerator generator = new OutputGenerator(
                sectorElements,
                outputGroups,
                new CompilableElementCollectorFactory(sectorElements, outputGroups)
                );

            foreach (AbstractOutputFile output in arguments.OutputFiles)
            {
                events.AddEvent(new CompilationMessage($"Generating {output.GetFileDescriptor()} output"));
                generator.GenerateOutput(output);
            }

            events.AddEvent(new CompilationFinishedEvent(true));
            return(0);
        }