示例#1
0
        public void TestMessageType24PartB()
        {
            const string sourceStringTypeA = "!AIVDM,1,1,,B,H>DQ@04N6DeihhlPPPPPPP000000,0*E";
            var          factory           = new SentenceFactory {
                IsCrcEnabled = true
            };
            var bytes    = Encoding.ASCII.GetBytes(sourceStringTypeA);
            var sentence = factory.CreateSentence(bytes);

            Assert.NotNull(sentence);

            bool fragmented;
            var  messageFactory = new CommonAisMessageFactory();

            var m = messageFactory.CreateAisMessage(sentence, out fragmented) as ClassBStaticAndVoyageDataMesageTypeB;

            Assert.NotNull(m);
            Assert.AreEqual(24, m.Type);
            Assert.AreEqual(1, m.PartNumber);
            Assert.AreEqual(961040384, m.Mmsi);
            Assert.AreEqual(0, m.RepeatIndicator);
            Assert.AreEqual(ShipType.Fishing, m.ShipType);
            Assert.AreEqual("FT-", m.VendorId);
            Assert.AreEqual(string.Empty, m.Callsign);
            Assert.AreEqual(0, m.Bow);
            Assert.AreEqual(0, m.Stern);
            Assert.AreEqual(0, m.Port);
            Assert.AreEqual(0, m.Starboard);
        }
示例#2
0
        public void TestAisMessageFactoryFragments()
        {
            var factory = new SentenceFactory {
                IsCrcEnabled = true
            };
            var sourceString = "!AIVDM,1,1,,A,13HOI:0P0000VOHLCnHQKwvL05Ip,0*23";
            var bytes        = Encoding.ASCII.GetBytes(sourceString);
            var sentence     = factory.CreateSentence(bytes);

            var  messageFactory = new CommonAisMessageFactory();
            bool fragmented;
            var  message1 = messageFactory.CreateAisMessage(sentence, out fragmented);

            Assert.IsFalse(fragmented);

            var fragment1 = "!AIVDM,2,1,8,A,569r?PP000000000000P4UQDr3737000000000000000040000000000,0*08";
            var fragment2 = "!AIVDM,2,2,8,A,000000000000000,2*2C";

            bytes = Encoding.ASCII.GetBytes(fragment1);
            var sentenceF1 = factory.CreateSentence(bytes);

            bytes = Encoding.ASCII.GetBytes(fragment2);
            var sentenceF2 = factory.CreateSentence(bytes);

            message1 = messageFactory.CreateAisMessage(sentenceF1, out fragmented);
            Assert.IsTrue(fragmented);

            message1 = messageFactory.CreateAisMessage(sentenceF2, out fragmented);
            Assert.IsFalse(fragmented);
        }
示例#3
0
        public void TestMessageType4()
        {
            const string sourceString = "!AIVDM,1,1,,B,4025;PAuho;N>0NJbfMRhNA00D3l,0*66";
            var          factory      = new SentenceFactory {
                IsCrcEnabled = true
            };
            var bytes    = Encoding.ASCII.GetBytes(sourceString);
            var sentence = factory.CreateSentence(bytes);

            Assert.NotNull(sentence);

            bool fragmented;
            var  messageFactory = new CommonAisMessageFactory();

            var m = messageFactory.CreateAisMessage(sentence, out fragmented) as BaseStationReportMessage;

            Assert.NotNull(m);
            Assert.AreEqual(4, m.Type);
            Assert.AreEqual(0, m.RepeatIndicator);
            Assert.AreEqual(002182017, m.Mmsi);

            //TODO:: Chech this, 128 or -128??
            Assert.AreEqual(2012, m.Year);
            Assert.AreEqual(3, m.Month);
            Assert.AreEqual(14, m.Day);
            Assert.AreEqual(11, m.Hour);
            Assert.AreEqual(30, m.Minute);
            Assert.AreEqual(14, m.Second);
            Assert.AreEqual(false, m.FixQuality);
            Assert.AreEqual(6.644625f, m.Longtitude);
            Assert.AreEqual(51.63028f, m.Latitude);
            Assert.AreEqual(EpfdFixType.Gps, m.PositionFixType);
            Assert.AreEqual(false, m.RaimFlag);
        }
示例#4
0
        public void TestMessageType18()
        {
            const string sourceString = "!AIVDM,1,1,,B,B43JRq00LhTWc5VejDI>wwWUoP06,0*29";
            var          factory      = new SentenceFactory {
                IsCrcEnabled = true
            };
            var bytes    = Encoding.ASCII.GetBytes(sourceString);
            var sentence = factory.CreateSentence(bytes);

            Assert.NotNull(sentence);

            bool fragmented;
            var  messageFactory = new CommonAisMessageFactory();

            var m = messageFactory.CreateAisMessage(sentence, out fragmented) as ClassBPositionReportMessage;

            Assert.NotNull(m);
            Assert.AreEqual(18, m.Type);
            Assert.AreEqual(0, m.RepeatIndicator);
            Assert.AreEqual(272016100, m.Mmsi);
            Assert.AreEqual(11.5f, m.SpeedOverGround);
            Assert.AreEqual(false, m.PositionAcuracy);
            Assert.AreEqual(31.9989529f, m.Longtitude);
            Assert.AreEqual(46.94412f, m.Latitude);
            Assert.AreEqual(126.3f, m.CourseOverGround);
            Assert.AreEqual(511, m.TrueHeading);
            Assert.AreEqual(15, m.UtcSeconds);
            Assert.AreEqual(true, m.RaimFlag);
            Assert.AreEqual(CsUnitType.ClassBCarrierSense, m.CsUnit);
            Assert.AreEqual(false, m.DisplayFlag);
            Assert.AreEqual(true, m.DscFlag);
            Assert.AreEqual(true, m.BandFlag);
            Assert.AreEqual(true, m.Message22Flag);
            Assert.AreEqual(false, m.AssignedMode);
        }
示例#5
0
        public void TestMessageType2()
        {
            const string sourceString = "!AIVDM,1,1,,B,24SaQh500G0Cu7nMErpJ680N0@9C,0*3F";
            var          factory      = new SentenceFactory {
                IsCrcEnabled = true
            };
            var bytes    = Encoding.ASCII.GetBytes(sourceString);
            var sentence = factory.CreateSentence(bytes);

            Assert.NotNull(sentence);

            bool fragmented;
            var  messageFactory = new CommonAisMessageFactory();

            var m = messageFactory.CreateAisMessage(sentence, out fragmented) as ClassAPositionReportMessage;

            Assert.NotNull(m);
            Assert.AreEqual(2, m.Type);
            Assert.AreEqual(0, m.RepeatIndicator);
            Assert.AreEqual(305816000, m.Mmsi);
            Assert.AreEqual(NavigationStatus.Moored, m.NavigationStatus);

            //TODO:: Chech this, 128 or -128??
            Assert.AreEqual(0, m.RateOfTurn);
            Assert.AreEqual(2.3f, m.SpeedOverGround);
            Assert.AreEqual(false, m.PositionAcuracy);
            Assert.AreEqual(4.3592450f, m.Longtitude);
            Assert.AreEqual(51.2797318f, m.Latitude);
            Assert.AreEqual(258.4f, m.CourseOverGround);
            Assert.AreEqual(256, m.TrueHeading);
            Assert.AreEqual(15, m.UtcSeconds);
            Assert.AreEqual(ManeuverIndicator.NotAvailable, m.ManeuverIndicator);
            Assert.AreEqual(0, m.Spare);
            Assert.AreEqual(false, m.RaimFlag);
        }
示例#6
0
        public void TestMessageType1()
        {
            const string sourceString = "!AIVDM,1,1,,A,13HOI:0P0000VOHLCnHQKwvL05Ip,0*23";
            var          factory      = new SentenceFactory {
                IsCrcEnabled = true
            };
            var bytes    = Encoding.ASCII.GetBytes(sourceString);
            var sentence = factory.CreateSentence(bytes);

            Assert.NotNull(sentence);

            bool fragmented;
            var  messageFactory = new CommonAisMessageFactory();

            var m = messageFactory.CreateAisMessage(sentence, out fragmented) as ClassAPositionReportMessage;

            Assert.NotNull(m);
            Assert.AreEqual(1, m.Type);
            Assert.AreEqual(0, m.RepeatIndicator);
            Assert.AreEqual(227006760, m.Mmsi);
            Assert.AreEqual(NavigationStatus.UnderWayUsingEngine, m.NavigationStatus);

            //TODO:: Chech this, 128 or -128??
            Assert.AreEqual(128, m.RateOfTurn);
            Assert.AreEqual(0.0, m.SpeedOverGround);
            Assert.AreEqual(false, m.PositionAcuracy);
            Assert.AreEqual(0.13138f, m.Longtitude);
            Assert.AreEqual(49.47558f, m.Latitude);
            Assert.AreEqual(36.7f, m.CourseOverGround);
            Assert.AreEqual(511, m.TrueHeading);
            Assert.AreEqual(14, m.UtcSeconds);
            Assert.AreEqual(ManeuverIndicator.NotAvailable, m.ManeuverIndicator);
            Assert.AreEqual(0, m.Spare);
            Assert.AreEqual(false, m.RaimFlag);
        }
示例#7
0
        public void TestJsonSerializer1()
        {
            const string sourceString = "!AIVDM,1,1,,A,13HOI:0P0000VOHLCnHQKwvL05Ip,0*23";
            var          factory      = new SentenceFactory {
                IsCrcEnabled = true
            };
            var bytes    = Encoding.ASCII.GetBytes(sourceString);
            var sentence = factory.CreateSentence(bytes);

            Assert.NotNull(sentence);

            bool fragmented;
            var  messageFactory = new CommonAisMessageFactory();

            var m = messageFactory.CreateAisMessage(sentence, out fragmented) as ClassAPositionReportMessage;

            Assert.NotNull(m);
            var serializer = new DataContractJsonSerializer(m.GetType());
            var stream     = new MemoryStream();

            serializer.WriteObject(stream, m);
            var bytesS = stream.ToArray();

            stream.Close();
            var str = Encoding.UTF8.GetString(bytesS, 0, bytesS.Length);

            Assert.NotNull(str);
        }
示例#8
0
        public TextDocumentReader(AnnotationSet annotationSet)
        {
            _sententceFactory = new SentenceFactory(annotationSet);

            InputLanguage  = Language.SimplifiedChinese;
            OutputEncoding = Encoding.UTF8;
        }
示例#9
0
        public void PresentSimple()
        {
            var sentence = SentenceFactory.CreateSentence("You do it");

            var @string = sentence.Negative().ToString();

            Assert.Equal("You do not do it", @string);
        }
示例#10
0
        public void FuturePerfectProgressive()
        {
            var sentence = SentenceFactory.CreateSentence("You do it");

            var str = sentence.Progressive().Perfect().Future().Negative().ToString();

            Assert.Equal("You will not have been doing it", str);
        }
示例#11
0
        public void PastSimple()
        {
            var sentence = SentenceFactory.CreateSentence("You do it");

            var str = sentence.Past().Negative().ToString();

            Assert.Equal("You did not do it", str);
        }
示例#12
0
        public void PastProgressive()
        {
            var sentence = SentenceFactory.CreateSentence("You do it");

            var str = sentence.Progressive().Past().Negative().ToString();

            Assert.Equal("You were not doing it", str);
        }
示例#13
0
        public void FutureSimple()
        {
            var sentence = SentenceFactory.CreateSentence("You do it");

            var str = sentence.Future().Negative().ToString();

            Assert.Equal("You will not do it", str);
        }
示例#14
0
        public void PresentSimple()
        {
            Sentence sentence = SentenceFactory.CreateSentence("He has it");

            string @string = sentence.ToString();

            Assert.Equal("He has it", @string);
        }
示例#15
0
        public void PresentPerfect()
        {
            var sentence = SentenceFactory.CreateSentence("You do it");

            var str = sentence.Perfect().Negative().ToString();

            Assert.Equal("You have not done it", str);
        }
示例#16
0
        public void FutureInThePastPerfectPassiveVoice()
        {
            var sentence = SentenceFactory.CreateSentence("I do by it");

            sentence.Passive().Perfect().Future().Past();
            var str = sentence.Negative().ToString();

            Assert.Equal("I should not have been done by it", str);
        }
示例#17
0
        public void FutureSimplePassiveVoice()
        {
            var sentence = SentenceFactory.CreateSentence("I do by it");

            sentence.Passive().Future();
            var str = sentence.Negative().ToString();

            Assert.Equal("I shall not be done by it", str);
        }
示例#18
0
        public void PastPerfectPassiveVoice()
        {
            var sentence = SentenceFactory.CreateSentence("I do by it");

            sentence.Passive().Perfect().Past();
            var str = sentence.Negative().ToString();

            Assert.Equal("I had not been done by it", str);
        }
示例#19
0
        public void PastProgressivePassiveVoice()
        {
            var sentence = SentenceFactory.CreateSentence("I do by it");

            sentence.Passive().Progressive().Past();
            var str = sentence.Negative().ToString();

            Assert.Equal("I was not being done by it", str);
        }
示例#20
0
        public void Simple()
        {
            Sentence sentence = SentenceFactory.CreateSentence("I do it");

            sentence.Future().Past();
            string str = sentence.ToString();

            Assert.Equal("I should do it", str);
        }
示例#21
0
        public void FutureSimple()
        {
            Sentence sentence = SentenceFactory.CreateSentence("I do by it");

            sentence.Passive().Future();
            string str = sentence.ToString();

            Assert.Equal("I shall be done by it", str);
        }
示例#22
0
        public void FutureInThePastSimple()
        {
            var sentence = SentenceFactory.CreateSentence("I do it");

            sentence.Future().Past();
            var str = sentence.Negative().ToString();

            Assert.Equal("I should not do it", str);
        }
示例#23
0
        public void PastProgressive()
        {
            Sentence sentence = SentenceFactory.CreateSentence("I do by it");

            sentence.Passive().Progressive().Past();
            string str = sentence.ToString();

            Assert.Equal("I was being done by it", str);
        }
示例#24
0
        public void FutureInThePastPerfect()
        {
            Sentence sentence = SentenceFactory.CreateSentence("I do by it");

            sentence.Passive().Perfect().Future().Past();
            string str = sentence.ToString();

            Assert.Equal("I should have been done by it", str);
        }
示例#25
0
        public void PastPerfect()
        {
            Sentence sentence = SentenceFactory.CreateSentence("I do by it");

            sentence.Passive().Perfect().Past();
            string str = sentence.ToString();

            Assert.Equal("I had been done by it", str);
        }
示例#26
0
        public void PastSimple()
        {
            Sentence sentence = SentenceFactory.CreateSentence("He has it");

            sentence.Past();

            string str = sentence.ToString();

            Assert.Equal("He had it", str);
        }
示例#27
0
        public void PresentProgressive()
        {
            Sentence sentence = SentenceFactory.CreateSentence("He has it");

            sentence.Progressive();

            string str = sentence.ToString();

            Assert.Equal("He is having it", str);
        }
示例#28
0
        public void PresentPerfect()
        {
            Sentence sentence = SentenceFactory.CreateSentence("He has it");

            sentence.Perfect();

            string str = sentence.ToString();

            Assert.Equal("He has had it", str);
        }
示例#29
0
        public void FutureSimple()
        {
            Sentence sentence = SentenceFactory.CreateSentence("He has it");

            sentence.Future();

            string str = sentence.ToString();

            Assert.Equal("He will have it", str);
        }
示例#30
0
        public void FuturePerfectProgressive()
        {
            Sentence sentence = SentenceFactory.CreateSentence("He has it");

            sentence.Progressive().Perfect().Future();

            string str = sentence.ToString();

            Assert.Equal("He will have been having it", str);
        }
示例#31
0
        public void PerfectProgressive()
        {
            Sentence sentence = SentenceFactory.CreateSentence("I do it");

            sentence.Progressive().Perfect().Future().Past();

            string str = sentence.ToString();

            Assert.Equal("I should have been doing it", str);
        }
示例#32
0
文件: Program.cs 项目: Ran-QUAN/Alta
        public void Start()
        {
            if (startCheck())
            {
                AnnotationSet wemas;
                ICTCLASAnnotator ictclasAno;
                CRFPPAnnotator crfppAno;
                Corpus corpus;

                Console.BackgroundColor = ConsoleColor.DarkBlue;
                Console.Clear();
                writeTitle();

                ConsoleColor color = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Green;

                try
                {
                    Console.WriteLine(MessageInitializing);

                    wemas = new AnnotationSet();
                    wemas.Load(_annotationSet);

                    ictclasAno = new ICTCLASAnnotator(wemas, null);
                    crfppAno = new CRFPPAnnotator(wemas,
                        new Model(_crfppModel));
                    crfppAno.SetCRFPPRootPath(_crfppDir);

                    corpus = new Corpus(Encoding.GetEncoding(_xmlEncoding));

                    Console.Write(MessageLoadingCorpus);
                    savePosition();

                    var documents = from file in Directory.GetFiles(_corpusDir)
                                    where file.ToUpper().EndsWith(".TXT")
                                    select file;

                    if (documents.Count() == 0)
                    {
                        Console.WriteLine();
                        Console.WriteLine(MessageEmptyCorpus);
                        Console.WriteLine(MessageDone);
                        Console.ForegroundColor = color;
                        pause();
                        return;
                    }

                    _sentenceFactory
                        = new SentenceFactory(wemas);
                    _sentenceFactory.InputLanguage
                        = Language.SimplifiedChinese;
                    _sentenceFactory.OutputEncoding = corpus.Encoding;

                    int count = 0;
                    foreach (var doc in documents)
                    {
                        Sentence[] sens = _sentenceFactory.GetSentences(
                            new FileStream(doc, FileMode.Open));

                        WEMDocument wDoc = new WEMDocument(corpus.Encoding);
                        wDoc.Name = doc;

                        foreach (var sen in sens)
                        {
                            wDoc.AddSentence(sen);
                        }

                        corpus.AddDocument(wDoc);

                        rewrite(String.Format("{0}%", (int)((double)
                        ++count / documents.Count() * 100)));
                    }

                    Console.WriteLine("共加载{0}篇文档。",
                        corpus.Documents.Count);
                    Console.Write(MessageAnnotatingSeg);
                    savePosition();

                    bool done = false;

                    ictclasAno.AnnotationProgressChanged += (s, ea) =>
                        {
                            rewrite(String.Format("{0}%",
                                Math.Round(ea.ProgressInDouble, 2) * 100));
                        };

                    ictclasAno.AnnotationCompleted += (s, ea) =>
                        {
                            if (ea.Error == null)
                            {
                                rewrite("100%");
                                Console.WriteLine(MessageAnnotatingEnt);

                                crfppAno.AnnotationProgressChanged += (sen, args) =>
                                    {
                                        Console.WriteLine(args.Message);
                                    };

                                crfppAno.AnnotationCompleted += (sen, args) =>
                                    {
                                        if (args.Error == null)
                                        {
                                            Console.WriteLine(
                                                                            MessageAnnotationFinished);
                                            if (_reportsEnabled)
                                                Console.Write(MessageSavingDocsAndReps);
                                            else
                                                Console.Write(MessageSavingDocuments);
                                            savePosition();

                                            int sCount = 0;
                                            foreach (var doc in corpus.Documents)
                                            {
                                                string reportFileName;

                                                string fileName = documents.ElementAt(
                                                    corpus.Documents.IndexOf(doc));

                                                FileInfo fi = new FileInfo(fileName);
                                                reportFileName = fileName = fi.Name;

                                                fileName = fileName.Remove(
                                                    fileName.Length - 3);
                                                fileName = _outputDir + fileName
                                                    + "xml";

                                                doc.Save(fileName);

                                                if (_reportsEnabled)
                                                    saveReport(doc,
                                                        _reportsDir + reportFileName,
                                                        wemas);

                                                rewrite(String.Format("{0}%",
                                                    (int)((double)++sCount
                                                    / corpus.Documents.Count * 100)));
                                            }

                                            Console.WriteLine(MessageDone);
                                            done = true;
                                        }
                                        else
                                        {
                                            Console.ForegroundColor = ConsoleColor.Red;
                                            Console.WriteLine();
                                            Console.WriteLine(MessageUnhandledException);
                                            Console.WriteLine(args.Error.Message);
                                            Console.WriteLine(args.Error.StackTrace);
                                            done = true;
                                        }
                                    };

                                if (crfppAno.Initialize())
                                {
                                    crfppAno.ProcessCorpusAsync(corpus);
                                }
                                else
                                {
                                    Console.ForegroundColor = ConsoleColor.Red;
                                    Console.WriteLine(MessageEntInitFailed);
                                    done = true;
                                    return;
                                }
                            }
                            else
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine();
                                Console.WriteLine(MessageUnhandledException);
                                Console.WriteLine(ea.Error.Message);
                                Console.WriteLine(ea.Error.StackTrace);
                                done = true;
                            }
                        };

                    if (ictclasAno.Initialize())
                    {
                        ictclasAno.ProcessCorpusAsync(corpus);

                        while (!done)
                            Thread.Sleep(50);
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(MessageSegInitFailed);
                    }
                }
                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine();
                    Console.WriteLine(MessageUnhandledException);
                    Console.WriteLine(ex.Message);
                }

                Console.ForegroundColor = color;
                //pause();
                return;
            }
            else
            {
                //();
                return;
            }
        }