/// <summary> /// Сопоставить файл с маской /// </summary> /// <param name="file">Файл для проверки</param> /// <returns>Возвращает true если файл подошёл по маске, false в противном случае.</returns> public bool CompareWithExpression(File file) { MaskHandler.currentFile = file; try { AntlrInputStream input = new AntlrInputStream(this.mask + "\n"); MaskLexer lexer = new MaskLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); MaskParser parser = new MaskParser(tokens); parser.mask(); if (final == true) { Result.result.Add(Path.GetFullPath(file.GetName())); return(true); } } catch (InputMismatchException error) { Console.WriteLine("Error"); } return(false); }
public Image <Rgb, byte> GetBodyImage(bool withhandle = false) { Image <Rgb, byte> body_img = new Image <Rgb, byte>(width, height); body_img.SetZero(); foreach (Vector2 p in this.body) { body_img[(int)p.y, (int)p.x] = new Rgb(255, 255, 255); } MaskParser.FillGap(body_img); //MaskParser.FillHole(body_img); if (withhandle) { List <Image <Rgb, byte> > handles = this.GetHandleImage(); foreach (Image <Rgb, byte> hi in handles) { hi.SetValue(new Rgb(255, 0, 0), hi.Convert <Gray, byte>()); CvInvoke.BitwiseOr(body_img, hi, body_img); } MaskParser.FillGap(body_img, 5); body_img.Save("xxx.png"); } //if (label == Label.Cylinder) //{ // body_img = MaskParser.FillBodyWithHandle(body_img, this.GetHandleImage()); //} return(body_img); }
public void CleanUp() { var parser = new MaskParser(_expectedMask); Assert.AreEqual(_expectedMask, parser.GetMaskFromTagsAndSplits()); CollectionAssert.AreEqual(_expectedTags, parser.GetTags()); CollectionAssert.AreEqual(_expectedSplits, parser.GetSplits()); }
public void MaskParser_IsEqualNumberOfSplitsInMaskAndFileName_ReturnFalse() { // arrange var _expectedMask = "{track}.{artist}{title}"; var parser = new MaskParser(_expectedMask); // act var actual = parser.IsEqualNumberOfSplitsInMaskAndFileName(".", "Alla.Pop.Arlekino"); // assert Assert.IsFalse(actual); }
public void ParseRawMask(Image <Rgb, byte> img) { MaskParser mp = new MaskParser(img); this.geometries = mp.Parse(); }
public void MaskParser_WithoutSplits_Exception() { var parser = new MaskParser("{artist}{track}"); parser.ValidateFileName("TestArtist1"); }
public void MaskParser_ManySplits_Exception() { var parser = new MaskParser("{artist}-{track}"); parser.ValidateFileName("Test-Artist-1"); }
public void MaskParser_SplitInBeginAndEnd_Successful() { var parser = new MaskParser("-{artist}.{track}-"); Assert.IsTrue(parser.ValidateFileName("-TestArtist.1-")); }
public void MaskParser_LetterInCenter_Successful() { var parser = new MaskParser("{artist}Q{track}"); Assert.IsTrue(parser.ValidateFileName("TestArtistQ1")); }
public void MaskParser_SameSplits_Successful() { var parser = new MaskParser("{artist} - {title} - {track}"); Assert.IsTrue(parser.ValidateFileName("TestArtist - TestTitle - 1")); }
public void MaskParser_SplitInBegin_Successful() { var parser = new MaskParser("a{artist}"); Assert.IsTrue(parser.ValidateFileName("aTestArtist")); }
public void MaskParser_Common_Successful() { var parser = new MaskParser("{artist} - {title}"); Assert.IsTrue(parser.ValidateFileName("TestArtist - TestTitle")); }