/// <summary>
        /// Learns a program to extract the surname from a given table row (rather than a whole document).
        /// </summary>
        public static void LearnSurnameWithRespectToTableRow()
        {
            string    s   = File.ReadAllText(Path.Combine(_sampleDocs, "sample-document-1.html"));
            HtmlDoc   doc = HtmlDoc.Create(s);
            WebRegion referenceRegion1 = doc.GetRegion("tr:nth-child(1)");                 //1st table row
            WebRegion exampleRegion1   = doc.GetRegion("tr:nth-child(1) td:nth-child(2)"); //2nd cell in 1st table row
            WebRegion referenceRegion2 = doc.GetRegion("tr:nth-child(2)");                 //2nd table row
            WebRegion exampleRegion2   = doc.GetRegion("tr:nth-child(2) td:nth-child(2)"); //2nd cell in 2nd table row
            CorrespondingMemberEquals <WebRegion, WebRegion> exampleSpec1 = new CorrespondingMemberEquals <WebRegion, WebRegion>(referenceRegion1, exampleRegion1);
            CorrespondingMemberEquals <WebRegion, WebRegion> exampleSpec2 = new CorrespondingMemberEquals <WebRegion, WebRegion>(referenceRegion2, exampleRegion2);

            Web.RegionProgram prog = Web.RegionLearner.Instance.Learn(new[] { exampleSpec1, exampleSpec2 });
            if (prog == null)
            {
                return;
            }
            //run the program on 5th table row
            WebRegion fifthRowRegion = doc.GetRegion("tr:nth-child(5)"); //5th table row
            WebRegion region         = prog.Run(new [] { fifthRowRegion })?.SingleOrDefault();

            Console.WriteLine("Learn surname with respect to table row: ");
            Console.WriteLine(region.GetSpecificSelector());
            Console.WriteLine(region.Text());
            Console.WriteLine();
        }
Example #2
0
        /// <summary>
        /// Learns a program to extract the surname from a given table row (rather than a whole document).
        /// </summary>
        public static void LearnSurnameWithRespectToTableRow()
        {
            string    s   = File.ReadAllText(@"..\..\SampleDocuments\sample-document-1.html");
            HtmlDoc   doc = HtmlDoc.Create(s);
            WebRegion referenceRegion1 = doc.GetRegion("tr:nth-child(1)");                 //1st table row
            WebRegion exampleRegion1   = doc.GetRegion("tr:nth-child(1) td:nth-child(2)"); //2nd cell in 1st table row
            WebRegion referenceRegion2 = doc.GetRegion("tr:nth-child(2)");                 //2nd table row
            WebRegion exampleRegion2   = doc.GetRegion("tr:nth-child(2) td:nth-child(2)"); //2nd cell in 2nd table row
            ExtractionExample <WebRegion> exampleSpec1 = new ExtractionExample <WebRegion>(referenceRegion1, exampleRegion1);
            ExtractionExample <WebRegion> exampleSpec2 = new ExtractionExample <WebRegion>(referenceRegion2, exampleRegion2);

            Web.Program prog = Web.Learner.Instance.LearnRegion(new[] { exampleSpec1, exampleSpec2 },
                                                                Enumerable.Empty <ExtractionExample <WebRegion> >());
            if (prog != null)
            {
                //run the program on 5th table row
                WebRegion fifthRowRegion = doc.GetRegion("tr:nth-child(5)"); //5th table row
                IEnumerable <WebRegion> executionResult = prog.Run(fifthRowRegion);
                foreach (WebRegion region in executionResult)
                {
                    Console.WriteLine("Learn surname with respect to table row: ");
                    Console.WriteLine(region.GetSpecificSelector());
                    Console.WriteLine(region.Text());
                    Console.WriteLine();
                }
            }
        }
        /// <summary>
        /// Learns a program and then serializes and deserializes it.
        /// </summary>
        public static void SerializeProgram()
        {
            string    s               = File.ReadAllText(Path.Combine(_sampleDocs, "sample-document-1.html"));
            HtmlDoc   doc             = HtmlDoc.Create(s);
            WebRegion referenceRegion = new WebRegion(doc);
            WebRegion exampleRegion   = doc.GetRegion("tr:nth-child(1) td:nth-child(2)"); //2nd cell in 1st table row
            CorrespondingMemberEquals <WebRegion, WebRegion> exampleSpec = new CorrespondingMemberEquals <WebRegion, WebRegion>(referenceRegion, exampleRegion);

            Web.RegionProgram prog = Web.RegionLearner.Instance.Learn(new[] { exampleSpec });
            if (prog == null)
            {
                return;
            }
            string progText = prog.Serialize();

            Web.RegionProgram       loadProg        = Web.Loader.Instance.Region.Load(progText);
            IEnumerable <WebRegion> executionResult = loadProg.Run(new[] { referenceRegion });

            Console.WriteLine("Run first surname extraction program after serialization and deserialization: ");
            foreach (WebRegion region in executionResult)
            {
                Console.WriteLine(region.GetSpecificSelector());
                Console.WriteLine(region.Text());
            }
            Console.WriteLine();
        }
Example #4
0
        /// <summary>
        /// Learns a program to extract the first surname in the document from two examples
        /// from two different documents.
        /// </summary>
        public static void LearnFirstSurnameInDocumentUsingMultipleExamples()
        {
            string    s1               = File.ReadAllText(@"..\..\SampleDocuments\sample-document-1.html");
            HtmlDoc   doc1             = HtmlDoc.Create(s1);
            string    s2               = File.ReadAllText(@"..\..\SampleDocuments\sample-document-2.html");
            HtmlDoc   doc2             = HtmlDoc.Create(s2);
            WebRegion referenceRegion1 = new WebRegion(doc1);
            WebRegion referenceRegion2 = new WebRegion(doc2);
            WebRegion exampleRegion1   = doc1.GetRegion("tr:nth-child(1) td:nth-child(2)"); //2nd cell in 1st table row of doc1
            WebRegion exampleRegion2   = doc2.GetRegion("tr:nth-child(1) td:nth-child(2)"); //2nd cell in 1st table row of doc2
            ExtractionExample <WebRegion> exampleSpec1 = new ExtractionExample <WebRegion>(referenceRegion1, exampleRegion1);
            ExtractionExample <WebRegion> exampleSpec2 = new ExtractionExample <WebRegion>(referenceRegion2, exampleRegion2);

            Web.Program prog = Web.Learner.Instance.LearnRegion(new[] { exampleSpec1, exampleSpec2 },
                                                                Enumerable.Empty <ExtractionExample <WebRegion> >());
            if (prog != null)
            {
                //run the program on the second document
                IEnumerable <WebRegion> executionResult = prog.Run(referenceRegion2);
                foreach (WebRegion region in executionResult)
                {
                    Console.WriteLine("Learn first surname in document from multiple examples: ");
                    Console.WriteLine(region.GetSpecificSelector());
                    Console.WriteLine(region.Text());
                    Console.WriteLine();
                }
            }
        }
Example #5
0
        public void Constructor()
        {
            WebRegion region;

            region = new WebRegion();
            Assert.IsNotNull(region);
        }
        public void LoadData()
        {
            Boolean      isRegionLoaded;
            List <Int32> regionCategoryIds;
            RegionGUID   regionGUID;
            WebRegion    region;

            isRegionLoaded    = false;
            regionCategoryIds = new List <Int32>();
            regionCategoryIds.Add(18);
            regionCategoryIds.Add(21);
            using (DataReader dataReader = Context.GetSpeciesObservationDatabase().GetCountyRegions())
            {
                while (dataReader.Read())
                {
                    isRegionLoaded = true;
                    region         = new WebRegion();
                    region.LoadData(dataReader);

                    Assert.IsTrue(0 <= region.CategoryId);
                    regionGUID = new RegionGUID(region.GUID);
                    Assert.AreEqual((object)region.CategoryId, regionGUID.CategoryId);
                    Assert.AreEqual((object)region.NativeId, regionGUID.NativeId);
                    Assert.IsTrue(0 <= region.Id);
                    Assert.IsTrue(region.Name.IsNotEmpty());
                    Assert.IsTrue(region.NativeId.IsNotEmpty());
                    // ShortName can have any value including null.
                    Assert.AreEqual(Int32.MinValue, region.SortOrder);
                }
            }
            Assert.IsTrue(isRegionLoaded);
        }
Example #7
0
 /// <summary>
 /// Learns a program to extract the first surname in the document from two examples 
 /// from two different documents.
 /// </summary>
 public static void LearnFirstSurnameInDocumentUsingMultipleExamples()
 {
     string s1 = File.ReadAllText(@"..\..\SampleDocuments\sample-document-1.html");
     HtmlDoc doc1 = HtmlDoc.Create(s1);
     string s2 = File.ReadAllText(@"..\..\SampleDocuments\sample-document-2.html");
     HtmlDoc doc2 = HtmlDoc.Create(s2);
     WebRegion referenceRegion1 = new WebRegion(doc1);
     WebRegion referenceRegion2 = new WebRegion(doc2);
     WebRegion exampleRegion1 = doc1.GetRegion("tr:nth-child(1) td:nth-child(2)"); //2nd cell in 1st table row of doc1
     WebRegion exampleRegion2 = doc2.GetRegion("tr:nth-child(1) td:nth-child(2)"); //2nd cell in 1st table row of doc2
     ExtractionExample<WebRegion> exampleSpec1 = new ExtractionExample<WebRegion>(referenceRegion1, exampleRegion1);
     ExtractionExample<WebRegion> exampleSpec2 = new ExtractionExample<WebRegion>(referenceRegion2, exampleRegion2);
     Web.Program prog = Web.Learner.Instance.LearnRegion(new[] { exampleSpec1, exampleSpec2 },
                                                                   Enumerable.Empty<ExtractionExample<WebRegion>>());
     if (prog != null)
     {
         //run the program on the second document 
         IEnumerable<WebRegion> executionResult = prog.Run(referenceRegion2);
         foreach (WebRegion region in executionResult)
         {
             Console.WriteLine("Learn first surname in document from multiple examples: ");
             Console.WriteLine(region.GetSpecificSelector());
             Console.WriteLine(region.Text());
             Console.WriteLine();
         }
     }
 }
        /// <summary>
        /// Learns a program to extract the first surname in the document from two examples
        /// from two different documents.
        /// </summary>
        public static void LearnFirstSurnameInDocumentUsingMultipleExamples()
        {
            string    s1               = File.ReadAllText(Path.Combine(_sampleDocs, "sample-document-1.html"));
            HtmlDoc   doc1             = HtmlDoc.Create(s1);
            string    s2               = File.ReadAllText(Path.Combine(_sampleDocs, "sample-document-2.html"));
            HtmlDoc   doc2             = HtmlDoc.Create(s2);
            WebRegion referenceRegion1 = new WebRegion(doc1);
            WebRegion referenceRegion2 = new WebRegion(doc2);
            WebRegion exampleRegion1   = doc1.GetRegion("tr:nth-child(1) td:nth-child(2)"); //2nd cell in 1st table row of doc1
            WebRegion exampleRegion2   = doc2.GetRegion("tr:nth-child(1) td:nth-child(2)"); //2nd cell in 1st table row of doc2
            CorrespondingMemberEquals <WebRegion, WebRegion> exampleSpec1 = new CorrespondingMemberEquals <WebRegion, WebRegion>(referenceRegion1, exampleRegion1);
            CorrespondingMemberEquals <WebRegion, WebRegion> exampleSpec2 = new CorrespondingMemberEquals <WebRegion, WebRegion>(referenceRegion2, exampleRegion2);

            Web.RegionProgram prog = Web.RegionLearner.Instance.Learn(new[] { exampleSpec1, exampleSpec2 });
            if (prog == null)
            {
                return;
            }
            //run the program on the second document
            WebRegion region = prog.Run(new [] { referenceRegion2 })?.SingleOrDefault();

            Console.WriteLine("Learn first surname in document from multiple examples: ");
            Console.WriteLine(region.GetSpecificSelector());
            Console.WriteLine(region.Text());
            Console.WriteLine();
        }
Example #9
0
 private WebRegion GetRegion(Boolean refresh)
 {
     if (_region.IsNull() || refresh)
     {
         _region = new WebRegion();
     }
     return(_region);
 }
        public async Task <ReturnedSaveFuncInfo> SaveAsync(SqlTransaction tr = null)
        {
            var           res      = new ReturnedSaveFuncInfo();
            var           autoTran = tr == null;
            SqlConnection cn       = null;

            try
            {
                if (autoTran)
                {
                    cn = new SqlConnection(Cache.ConnectionString);
                    await cn.OpenAsync();

                    tr = cn.BeginTransaction();
                }

                res.AddReturnedValue(CheckValidation());
                if (res.HasError)
                {
                    return(res);
                }

                res.AddReturnedValue(await UnitOfWork.Regions.SaveAsync(this, tr));
                if (res.HasError)
                {
                    return(res);
                }

                var action = IsModified ? EnLogAction.Update : EnLogAction.Insert;
                res.AddReturnedValue(await UserLogBussines.SaveAsync(action, EnLogPart.Regions, tr));
                if (res.HasError)
                {
                    return(res);
                }

                if (Cache.IsSendToServer)
                {
                    _ = Task.Run(() => WebRegion.SaveAsync(this));
                }
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }
            finally
            {
                if (autoTran)
                {
                    res.AddReturnedValue(tr.TransactionDestiny(res.HasError));
                    res.AddReturnedValue(cn.CloseConnection());
                }
            }
            return(res);
        }
 /// <summary>
 /// Get region from WebRegion.
 /// </summary>
 /// <param name="userContext">User context.</param>
 /// <param name="webRegion">WebRegion.</param>
 /// <returns>Region.</returns>
 protected IRegion GetRegion(IUserContext userContext, WebRegion webRegion)
 {
     return(new Region(webRegion.Id,
                       webRegion.CategoryId,
                       webRegion.GUID,
                       webRegion.Name,
                       webRegion.NativeId,
                       webRegion.ShortName,
                       webRegion.SortOrder,
                       GetDataContext(userContext)));
 }
Example #12
0
 /// <summary>
 /// Load data into the WebRegion instance.
 /// </summary>
 /// <param name="region">This region.</param>
 /// <param name='dataReader'>An open data reader.</param>
 public static void LoadData(this WebRegion region,
                             DataReader dataReader)
 {
     region.CategoryId = dataReader.GetInt32(RegionData.CATEGORY_ID);
     region.Id         = dataReader.GetInt32(RegionData.ID);
     region.Name       = dataReader.GetString(RegionData.NAME);
     region.NativeId   = dataReader.GetString(RegionData.NATIVE_ID);
     region.ShortName  = dataReader.GetString(RegionData.SHORT_NAME);
     region.SortOrder  = Int32.MinValue;
     region.GUID       = new RegionGUID(region.CategoryId, region.NativeId).GUID;
 }
        public static async Task <ReturnedSaveFuncInfo> SaveRangeAsync(List <RegionsBussines> list, SqlTransaction tr = null)
        {
            var           res      = new ReturnedSaveFuncInfo();
            var           autoTran = tr == null;
            SqlConnection cn       = null;

            try
            {
                if (autoTran)
                {
                    cn = new SqlConnection(Cache.ConnectionString);
                    await cn.OpenAsync();

                    tr = cn.BeginTransaction();
                }

                res.AddReturnedValue(await UnitOfWork.Regions.SaveRangeAsync(list, tr));
                if (res.HasError)
                {
                    return(res);
                }

                if (Cache.IsSendToServer)
                {
                    _ = Task.Run(() => WebRegion.SaveAsync(list));
                }
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }
            finally
            {
                if (autoTran)
                {
                    res.AddReturnedValue(tr.TransactionDestiny(res.HasError));
                    res.AddReturnedValue(cn.CloseConnection());
                }
            }
            return(res);
        }
        /// <summary>
        /// Learns a program to extract the surname from a given table row (rather than a whole document)
        /// using a negative example.
        /// </summary>
        public static void LearnSurnameWithRespectToTableRowUsingNegativeExample()
        {
            string    s   = File.ReadAllText(Path.Combine(_sampleDocs, "sample-document-1.html"));
            HtmlDoc   doc = HtmlDoc.Create(s);
            WebRegion referenceRegion1 = doc.GetRegion("tr:nth-child(1)"); //1st table row
            WebRegion referenceRegion2 = doc.GetRegion("tr:nth-child(2)"); //2nd table row
            var       posExampleSpec   = new CorrespondingMemberEquals <WebRegion, WebRegion>(referenceRegion1, doc.GetRegion("tr:nth-child(1) td:nth-child(2)"));
            var       negExampleSpec   = new CorrespondingMemberDoesNotEqual <WebRegion, WebRegion>(referenceRegion2, doc.GetRegion("tr:nth-child(2) td:nth-child(1)"));

            Web.RegionProgram prog = Web.RegionLearner.Instance.Learn(new Constraint <IEnumerable <WebRegion>, IEnumerable <WebRegion> >[] { posExampleSpec, negExampleSpec });
            if (prog == null)
            {
                return;
            }
            WebRegion region = prog.Run(new [] { referenceRegion1 })?.SingleOrDefault();

            Console.WriteLine("Learn surname with respect to table row using negative example: ");
            Console.WriteLine(region.GetSpecificSelector());
            Console.WriteLine(region.Text());
            Console.WriteLine();
        }
Example #15
0
 /// <summary>
 /// Learns a program to extract the first surname in the document from one example.
 /// </summary>
 public static void LearnFirstSurnameInDocumentUsingOneExample()
 {
     string s = File.ReadAllText(@"..\..\SampleDocuments\sample-document-1.html");
     HtmlDoc doc = HtmlDoc.Create(s);
     WebRegion referenceRegion = new WebRegion(doc);
     WebRegion exampleRegion = doc.GetRegion("tr:nth-child(1) td:nth-child(2)"); //2nd cell in 1st table row
     ExtractionExample<WebRegion> exampleSpec = new ExtractionExample<WebRegion>(referenceRegion, exampleRegion);
     Web.Program prog = Web.Learner.Instance.LearnRegion(new[] { exampleSpec }, Enumerable.Empty<ExtractionExample<WebRegion>>());
     if (prog != null)
     {
         //run the program to extract first surname from the document
         IEnumerable<WebRegion> executionResult = prog.Run(referenceRegion);
         foreach (WebRegion region in executionResult)
         {
             Console.WriteLine("Learn first surname in document from one example: ");
             Console.WriteLine(region.GetSpecificSelector());
             Console.WriteLine(region.Text());
             Console.WriteLine();
         }
     }
 }
        /// <summary>
        /// Learns a program to extract the first surname in the document from one example.
        /// </summary>
        public static void LearnFirstSurnameInDocumentUsingOneExample()
        {
            string    s               = File.ReadAllText(Path.Combine(_sampleDocs, "sample-document-1.html"));
            HtmlDoc   doc             = HtmlDoc.Create(s);
            WebRegion referenceRegion = new WebRegion(doc);
            WebRegion exampleRegion   = doc.GetRegion("tr:nth-child(1) td:nth-child(2)"); //2nd cell in 1st table row
            CorrespondingMemberEquals <WebRegion, WebRegion> exampleSpec = new CorrespondingMemberEquals <WebRegion, WebRegion>(referenceRegion, exampleRegion);

            Web.RegionProgram prog = Web.RegionLearner.Instance.Learn(new[] { exampleSpec });
            if (prog == null)
            {
                return;
            }
            //run the program to extract first surname from the document
            WebRegion region = prog.Run(new [] { referenceRegion })?.SingleOrDefault();

            Console.WriteLine("Learn first surname in document from one example: ");
            Console.WriteLine(region.GetSpecificSelector());
            Console.WriteLine(region.Text());
            Console.WriteLine();
        }
Example #17
0
        /// <summary>
        /// Learns a program to extract the first surname in the document from one example.
        /// </summary>
        public static void LearnFirstSurnameInDocumentUsingOneExample()
        {
            string    s               = File.ReadAllText(@"..\..\SampleDocuments\sample-document-1.html");
            HtmlDoc   doc             = HtmlDoc.Create(s);
            WebRegion referenceRegion = new WebRegion(doc);
            WebRegion exampleRegion   = doc.GetRegion("tr:nth-child(1) td:nth-child(2)"); //2nd cell in 1st table row
            ExtractionExample <WebRegion> exampleSpec = new ExtractionExample <WebRegion>(referenceRegion, exampleRegion);

            Web.Program prog = Web.Learner.Instance.LearnRegion(new[] { exampleSpec }, Enumerable.Empty <ExtractionExample <WebRegion> >());
            if (prog != null)
            {
                //run the program to extract first surname from the document
                IEnumerable <WebRegion> executionResult = prog.Run(referenceRegion);
                foreach (WebRegion region in executionResult)
                {
                    Console.WriteLine("Learn first surname in document from one example: ");
                    Console.WriteLine(region.GetSpecificSelector());
                    Console.WriteLine(region.Text());
                    Console.WriteLine();
                }
            }
        }
Example #18
0
        /// <summary>
        /// Learns a program and then serializes and deserializes it.
        /// </summary>
        public static void SerializeProgram()
        {
            string    s               = File.ReadAllText(@"..\..\SampleDocuments\sample-document-1.html");
            HtmlDoc   doc             = HtmlDoc.Create(s);
            WebRegion referenceRegion = new WebRegion(doc);
            WebRegion exampleRegion   = doc.GetRegion("tr:nth-child(1) td:nth-child(2)"); //2nd cell in 1st table row
            ExtractionExample <WebRegion> exampleSpec = new ExtractionExample <WebRegion>(referenceRegion, exampleRegion);

            Web.Program prog = Web.Learner.Instance.LearnRegion(new[] { exampleSpec }, Enumerable.Empty <ExtractionExample <WebRegion> >());
            if (prog != null)
            {
                string                  progText        = prog.Serialize();
                Web.Program             loadProg        = Web.Program.Load(progText);
                IEnumerable <WebRegion> executionResult = loadProg.Run(referenceRegion);
                Console.WriteLine("Run first surname extraction program after serialization and deserialization: ");
                foreach (WebRegion region in executionResult)
                {
                    Console.WriteLine(region.GetSpecificSelector());
                    Console.WriteLine(region.Text());
                }
                Console.WriteLine();
            }
        }
Example #19
0
        /// <summary>
        /// Learns a program to extract the sequence of all surnames in a document.
        /// </summary>
        public static void LearnAllSurnamesInDocument()
        {
            string    s               = File.ReadAllText(@"..\..\SampleDocuments\sample-document-1.html");
            HtmlDoc   doc             = HtmlDoc.Create(s);
            WebRegion referenceRegion = new WebRegion(doc);
            WebRegion exampleRegion1  = doc.GetRegion("tr:nth-child(1) td:nth-child(2)"); //2nd cell in 1st table row of doc
            WebRegion exampleRegion2  = doc.GetRegion("tr:nth-child(2) td:nth-child(2)"); //2nd cell in 2nd table row of doc
            ExtractionExample <WebRegion> exampleSpec1 = new ExtractionExample <WebRegion>(referenceRegion, exampleRegion1);
            ExtractionExample <WebRegion> exampleSpec2 = new ExtractionExample <WebRegion>(referenceRegion, exampleRegion2);

            Web.Program prog = Web.Learner.Instance.LearnSequence(new[] { exampleSpec1, exampleSpec2 }, Enumerable.Empty <ExtractionExample <WebRegion> >());
            if (prog != null)
            {
                IEnumerable <WebRegion> executionResult = prog.Run(referenceRegion);
                Console.WriteLine("Learn all surnames in document: ");
                foreach (WebRegion region in executionResult)
                {
                    Console.WriteLine(region.GetSpecificSelector());
                    Console.WriteLine(region.Text());
                }
                Console.WriteLine();
            }
        }
Example #20
0
        /// <summary>
        /// Learns a program to extract the surname from a given table row (rather than a whole document)
        /// using a negative example.
        /// </summary>
        public static void LearnSurnameWithRespectToTableRowUsingNegativeExample()
        {
            string    s   = File.ReadAllText(@"..\..\SampleDocuments\sample-document-1.html");
            HtmlDoc   doc = HtmlDoc.Create(s);
            WebRegion referenceRegion1 = doc.GetRegion("tr:nth-child(1)"); //1st table row
            WebRegion referenceRegion2 = doc.GetRegion("tr:nth-child(2)"); //2nd table row
            ExtractionExample <WebRegion> posExampleSpec = new ExtractionExample <WebRegion>(referenceRegion1, doc.GetRegion("tr:nth-child(1) td:nth-child(2)"));
            ExtractionExample <WebRegion> negExampleSpec = new ExtractionExample <WebRegion>(referenceRegion2, doc.GetRegion("tr:nth-child(2) td:nth-child(1)"));

            Web.Program prog = Web.Learner.Instance.LearnRegion(new[] { posExampleSpec },
                                                                new[] { negExampleSpec });
            if (prog != null)
            {
                IEnumerable <WebRegion> executionResult = prog.Run(referenceRegion1);
                foreach (WebRegion region in executionResult)
                {
                    Console.WriteLine("Learn surname with respect to table row using negative example: ");
                    Console.WriteLine(region.GetSpecificSelector());
                    Console.WriteLine(region.Text());
                    Console.WriteLine();
                }
            }
        }
        /// <summary>
        /// Learns a program to extract the sequence of all surnames in a document.
        /// </summary>
        public static void LearnAllSurnamesInDocument()
        {
            string    s               = File.ReadAllText(Path.Combine(_sampleDocs, "sample-document-1.html"));
            HtmlDoc   doc             = HtmlDoc.Create(s);
            WebRegion referenceRegion = new WebRegion(doc);
            WebRegion exampleRegion1  = doc.GetRegion("tr:nth-child(1) td:nth-child(2)"); //2nd cell in 1st table row of doc
            WebRegion exampleRegion2  = doc.GetRegion("tr:nth-child(2) td:nth-child(2)"); //2nd cell in 2nd table row of doc
            var       exampleSpec     = new MemberSubset <WebRegion, WebRegion>(referenceRegion, new[] { exampleRegion1, exampleRegion2 });

            Web.SequenceProgram prog = Web.SequenceLearner.Instance.Learn(new[] { exampleSpec });
            if (prog == null)
            {
                return;
            }
            IEnumerable <WebRegion> executionResult = prog.Run(new [] { referenceRegion })?.SingleOrDefault();

            Console.WriteLine("Learn all surnames in document: ");
            foreach (WebRegion region in executionResult)
            {
                Console.WriteLine(region.GetSpecificSelector());
                Console.WriteLine(region.Text());
            }
            Console.WriteLine();
        }
Example #22
0
 public WebRegionTest()
 {
     _region = null;
 }
Example #23
0
 /// <summary>
 /// Learns a program to extract the sequence of all surnames in a document.
 /// </summary>
 public static void LearnAllSurnamesInDocument()
 {
     string s = File.ReadAllText(@"..\..\SampleDocuments\sample-document-1.html");
     HtmlDoc doc = HtmlDoc.Create(s);
     WebRegion referenceRegion = new WebRegion(doc);
     WebRegion exampleRegion1 = doc.GetRegion("tr:nth-child(1) td:nth-child(2)"); //2nd cell in 1st table row of doc
     WebRegion exampleRegion2 = doc.GetRegion("tr:nth-child(2) td:nth-child(2)"); //2nd cell in 2nd table row of doc
     ExtractionExample<WebRegion> exampleSpec1 = new ExtractionExample<WebRegion>(referenceRegion, exampleRegion1);
     ExtractionExample<WebRegion> exampleSpec2 = new ExtractionExample<WebRegion>(referenceRegion, exampleRegion2);
     Web.Program prog = Web.Learner.Instance.LearnSequence(new[] { exampleSpec1, exampleSpec2 }, Enumerable.Empty<ExtractionExample<WebRegion>>());
     if (prog != null)
     {
         IEnumerable<WebRegion> executionResult = prog.Run(referenceRegion);
         Console.WriteLine("Learn all surnames in document: ");
         foreach (WebRegion region in executionResult)
         {
             Console.WriteLine(region.GetSpecificSelector());
             Console.WriteLine(region.Text());
         }
         Console.WriteLine();
     }
 }
Example #24
0
 /// <summary>
 /// Learns a program and then serializes and deserializes it.
 /// </summary>
 public static void SerializeProgram()
 {
     string s = File.ReadAllText(@"..\..\SampleDocuments\sample-document-1.html");
     HtmlDoc doc = HtmlDoc.Create(s);
     WebRegion referenceRegion = new WebRegion(doc);
     WebRegion exampleRegion = doc.GetRegion("tr:nth-child(1) td:nth-child(2)"); //2nd cell in 1st table row
     ExtractionExample<WebRegion> exampleSpec = new ExtractionExample<WebRegion>(referenceRegion, exampleRegion);
     Web.Program prog = Web.Learner.Instance.LearnRegion(new[] { exampleSpec }, Enumerable.Empty<ExtractionExample<WebRegion>>());
     if (prog != null)
     { 
         string progText = prog.Serialize();
         Web.Program loadProg = Web.Program.Load(progText);
         IEnumerable<WebRegion> executionResult = loadProg.Run(referenceRegion);
         Console.WriteLine("Run first surname extraction program after serialization and deserialization: ");
         foreach (WebRegion region in executionResult)
         {
             Console.WriteLine(region.GetSpecificSelector());
             Console.WriteLine(region.Text());
         }
         Console.WriteLine();
     }
 }
Example #25
0
        private static async Task StartSendToServerAsync()
        {
            try
            {
                var list = await TempBussines.GetAllAsync();

                while (true)
                {
                    if (list == null || list.Count <= 0)
                    {
                        await Task.Delay(2000);

                        continue;
                    }
                    foreach (var item in list)
                    {
                        switch (item.Type)
                        {
                        case EnTemp.States:
                            var states = await StatesBussines.GetAsync(item.ObjectGuid);

                            if (states != null)
                            {
                                await WebStates.SaveAsync(states);
                            }
                            break;

                        case EnTemp.Cities:
                            var city = await CitiesBussines.GetAsync(item.ObjectGuid);

                            if (city != null)
                            {
                                await WebCity.SaveAsync(city);
                            }
                            break;

                        case EnTemp.Region:
                            var region = await RegionsBussines.GetAsync(item.ObjectGuid);

                            if (region != null)
                            {
                                await WebRegion.SaveAsync(region);
                            }
                            break;

                        case EnTemp.Users:
                            var user = await UserBussines.GetAsync(item.ObjectGuid);

                            if (user != null)
                            {
                                await WebUser.SaveAsync(user);
                            }
                            break;

                        case EnTemp.PeopleGroups:
                            var pg = await PeopleGroupBussines.GetAsync(item.ObjectGuid);

                            if (pg != null)
                            {
                                await WebPeopleGroup.SaveAsync(pg);
                            }
                            break;

                        case EnTemp.Peoples:
                            var p = await PeoplesBussines.GetAsync(item.ObjectGuid);

                            if (p != null)
                            {
                                await WebPeople.SaveAsync(p);
                            }
                            break;

                        case EnTemp.BuildingAccountType:
                            var acc = await BuildingAccountTypeBussines.GetAsync(item.ObjectGuid);

                            if (acc != null)
                            {
                                await WebBuildingAccountType.SaveAsync(acc);
                            }
                            break;

                        case EnTemp.BuildingCondition:
                            var co = await BuildingConditionBussines.GetAsync(item.ObjectGuid);

                            if (co != null)
                            {
                                await WebBuildingCondition.SaveAsync(co);
                            }
                            break;

                        case EnTemp.BuildingType:
                            var type = await BuildingTypeBussines.GetAsync(item.ObjectGuid);

                            if (type != null)
                            {
                                await WebBuildingType.SaveAsync(type);
                            }
                            break;

                        case EnTemp.BuildingView:
                            var view = await BuildingViewBussines.GetAsync(item.ObjectGuid);

                            if (view != null)
                            {
                                await WebBuildingView.SaveAsync(view);
                            }
                            break;

                        case EnTemp.DocumentType:
                            var doc = await DocumentTypeBussines.GetAsync(item.ObjectGuid);

                            if (doc != null)
                            {
                                await WebDocumentType.SaveAsync(doc);
                            }
                            break;

                        case EnTemp.FloorCover:
                            var fc = await FloorCoverBussines.GetAsync(item.ObjectGuid);

                            if (fc != null)
                            {
                                await WebFloorCover.SaveAsync(fc);
                            }
                            break;

                        case EnTemp.KitchenService:
                            var ks = await KitchenServiceBussines.GetAsync(item.ObjectGuid);

                            if (ks != null)
                            {
                                await WebKitchenService.SaveAsync(ks);
                            }
                            break;

                        case EnTemp.RentalAuthority:
                            var ra = await RentalAuthorityBussines.GetAsync(item.ObjectGuid);

                            if (ra != null)
                            {
                                await WebRental.SaveAsync(ra);
                            }
                            break;

                        case EnTemp.BuildingOptions:
                            var o = await BuildingOptionsBussines.GetAsync(item.ObjectGuid);

                            if (o != null)
                            {
                                await WebBuildingOptions.SaveAsync(o);
                            }
                            break;

                        case EnTemp.Building:
                            var bu = await BuildingBussines.GetAsync(item.ObjectGuid);

                            if (bu != null)
                            {
                                await WebBuilding.SaveAsync(bu, Application.StartupPath);
                            }
                            break;

                        case EnTemp.Contract:
                            var con = await ContractBussines.GetAsync(item.ObjectGuid);

                            if (con != null)
                            {
                                await WebContract.SaveAsync(con);
                            }
                            break;

                        case EnTemp.Requests:
                            var req = await BuildingRequestBussines.GetAsync(item.ObjectGuid);

                            if (req != null)
                            {
                                await WebBuildingRequest.SaveAsync(req);
                            }
                            break;

                        case EnTemp.Reception:
                            var rec = await ReceptionBussines.GetAsync(item.ObjectGuid);

                            if (rec != null)
                            {
                                await WebReception.SaveAsync(rec);
                            }
                            break;

                        case EnTemp.Pardakht:
                            var pa = await PardakhtBussines.GetAsync(item.ObjectGuid);

                            if (pa != null)
                            {
                                await WebPardakht.SaveAsync(pa);
                            }
                            break;

                        case EnTemp.BuildingRelatedOptions:
                            var re = await BuildingRelatedOptionsBussines.GetAsync(item.ObjectGuid);

                            if (re != null)
                            {
                                await WebBuildingRelatedOptions.SaveAsync(re);
                            }
                            break;

                        case EnTemp.RequestRegions:
                            var rr = await BuildingRequestRegionBussines.GetAsync(item.ObjectGuid);

                            if (rr != null)
                            {
                                await WebBuildingRequestRegion.SaveAsync(rr);
                            }
                            break;

                        case EnTemp.PhoneBook:
                            var ph = await PhoneBookBussines.GetAsync(item.ObjectGuid);

                            if (ph != null)
                            {
                                await WebPhoneBook.SaveAsync(ph);
                            }
                            break;

                        case EnTemp.Advisor:
                            var ad = await AdvisorBussines.GetAsync(item.ObjectGuid);

                            if (ad != null)
                            {
                                await WebAdvisor.SaveAsync(ad);
                            }
                            break;

                        case EnTemp.Bank:
                            var ba = await BankBussines.GetAsync(item.ObjectGuid);

                            if (ba != null)
                            {
                                await WebBank.SaveAsync(ba);
                            }
                            break;

                        case EnTemp.Kol:
                            var kol = await KolBussines.GetAsync(item.ObjectGuid);

                            if (kol != null)
                            {
                                await WebKol.SaveAsync(kol);
                            }
                            break;

                        case EnTemp.Moein:
                            var moein = await MoeinBussines.GetAsync(item.ObjectGuid);

                            if (moein != null)
                            {
                                await WebMoein.SaveAsync(moein);
                            }
                            break;

                        case EnTemp.Tafsil:
                            var tafsil = await TafsilBussines.GetAsync(item.ObjectGuid);

                            if (tafsil != null)
                            {
                                await WebTafsil.SaveAsync(tafsil);
                            }
                            break;

                        case EnTemp.Sanad:
                            var sa = await SanadBussines.GetAsync(item.ObjectGuid);

                            if (sa != null)
                            {
                                await WebSanad.SaveAsync(sa);
                            }
                            break;

                        case EnTemp.SanadDetail:
                            var saD = await SanadDetailBussines.GetAsync(item.ObjectGuid);

                            if (saD != null)
                            {
                                await WebSanadDetail.SaveAsync(saD);
                            }
                            break;
                        }

                        await item.RemoveAsync();
                    }

                    await Task.Delay(2000);

                    list = await TempBussines.GetAllAsync();
                }
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
            }
        }
        private async Task ResendDataToHost()
        {
            try
            {
                if (chbState.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebStates.SaveAsync(await StatesBussines.GetAllAsync(_token.Token));
                }
                if (chbCity.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebCity.SaveAsync(await CitiesBussines.GetAllAsync(_token.Token));
                }
                if (chbRegion.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebRegion.SaveAsync(await RegionsBussines.GetAllAsync(_token.Token));
                }
                if (chbUsers.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebUser.SaveAsync(await UserBussines.GetAllAsync(_token.Token));
                }
                if (chbPeopleGroup.Checked)
                {
                    await WebPeopleGroup.SaveAsync(await PeopleGroupBussines.GetAllAsync());
                }
                if (chbPeople.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebPeople.SaveAsync(await PeoplesBussines.GetAllAsync(_token.Token));
                }
                if (chbAccountType.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebBuildingAccountType.SaveAsync(await BuildingAccountTypeBussines.GetAllAsync(_token.Token));
                }
                if (chbCondition.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebBuildingCondition.SaveAsync(await BuildingConditionBussines.GetAllAsync(_token.Token));
                }
                if (chbType.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebBuildingType.SaveAsync(await BuildingTypeBussines.GetAllAsync(_token.Token));
                }
                if (chbView.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebBuildingView.SaveAsync(await BuildingViewBussines.GetAllAsync(_token.Token));
                }
                if (chbDocType.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebDocumentType.SaveAsync(await DocumentTypeBussines.GetAllAsync(_token.Token));
                }

                if (chbFloor.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebFloorCover.SaveAsync(await FloorCoverBussines.GetAllAsync(_token.Token));
                }

                if (chbKitchen.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebKitchenService.SaveAsync(await KitchenServiceBussines.GetAllAsync(_token.Token));
                }

                if (chbRental.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebRental.SaveAsync(await RentalAuthorityBussines.GetAllAsync(_token.Token));
                }

                if (chbOptions.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebBuildingOptions.SaveAsync(await BuildingOptionsBussines.GetAllAsync(_token.Token));
                }

                if (chbBuilding.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebBuilding.SaveAsync(await BuildingBussines.GetAllAsync(_token.Token), Application.StartupPath);
                }


                if (chbRequest.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebBuildingRequest.SaveAsync(await BuildingRequestBussines.GetAllAsync(_token.Token));
                }

                if (chbContract.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebContract.SaveAsync(await ContractBussines.GetAllAsync(_token.Token));
                }
                if (chbReception.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebReception.SaveAsync(await ReceptionBussines.GetAllAsync(_token.Token));
                }

                if (chbPardakht.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebPardakht.SaveAsync(await PardakhtBussines.GetAllAsync(_token.Token));
                }

                if (chbAdvisor.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebAdvisor.SaveAsync(await AdvisorBussines.GetAllAsync(_token.Token));
                }

                if (chbBank.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebBank.SaveAsync(await BankBussines.GetAllAsync(_token.Token));
                }

                if (chbKol.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebKol.SaveAsync(await KolBussines.GetAllAsync(_token.Token));
                }

                if (chbMoein.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebMoein.SaveAsync(await MoeinBussines.GetAllAsync(_token.Token));
                }

                if (chbTafsil.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebTafsil.SaveAsync(await TafsilBussines.GetAllAsync(_token.Token));
                }

                if (chbSanad.Checked)
                {
                    _token?.Cancel();
                    _token = new CancellationTokenSource();
                    await WebSanad.SaveAsync(await SanadBussines.GetAllAsync(_token.Token));
                }


                Invoke(new MethodInvoker(() => MessageBox.Show("انتقال داده ها به سرور با موفقیت انجام شد")));
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
            }
            finally
            {
                Invoke(new MethodInvoker(() =>
                {
                    btnSend.Enabled = true;
                    Cursor          = Cursors.Default;
                }));
            }
        }