Beispiel #1
0
 def testSimple(self):
     text = "Patati patata patata tata vies"
     v = verse.Verse(text, template.Template(), plint.pattern.Pattern("12"))
     v.parse()
     gend = v.genders()
     self.assertEqual(1, len(gend))
     self.assertEqual('F', next(iter(gend)))
Beispiel #2
0
 def testSingleSyllNoHyphen(self):
     text = "Patati patata patata mange les"
     v = verse.Verse(text, template.Template(), plint.pattern.Pattern("12"))
     v.parse()
     gend = v.genders()
     self.assertTrue(v.valid())
     self.assertEqual(1, len(gend))
     self.assertEqual('M', next(iter(gend)))
Beispiel #3
0
 def testSingleSyllJe(self):
     text = "Patati patata patatatah où suis-je"
     v = verse.Verse(text, template.Template(), plint.pattern.Pattern("12"))
     v.parse()
     gend = v.genders()
     self.assertTrue(v.valid())
     self.assertEqual(1, len(gend))
     self.assertEqual('F', next(iter(gend)))
Beispiel #4
0
def main():
    global template
    localization.init_locale()
    parser = argparse.ArgumentParser(
        description=_("Check poem on stdin according to a template"))
    parser.add_argument(
        "template",
        help=_("the file containing the template for the input poem"),
        type=str)
    parser.add_argument("--format",
                        type=str,
                        help=_("error output format (text or json)"),
                        choices=["text", "json"],
                        default="text")
    parser.add_argument("--diaeresis",
                        type=str,
                        help=_("diaeresis training: diaeresis file to use"),
                        default="data/diaeresis.json")
    parser.add_argument(
        "--ocontext",
        type=str,
        help=_("diaeresis training: output file where to write the contexts"),
        default=None)
    parser.add_argument(
        "--weight",
        type=int,
        help=_("diaeresis training: fixed weight for a specific chunk"),
        default=None)
    parser.add_argument(
        "--offset",
        type=int,
        help=_(
            "diaeresis training: position of the specific chunk from the end"),
        default=0)
    args = parser.parse_args()

    template_name = args.template
    diaeresis.set_diaeresis(args.diaeresis)

    f = open(template_name)
    x = f.read()
    f.close()

    try:
        template = template.Template(x)
    except error.TemplateLoadError as e:
        print(_("Could not load template %s: %s") % (template_name, e.msg),
              file=sys.stderr)
        sys.exit(2)
    ok = run(ocontext=args.ocontext,
             weight=args.weight,
             offset=args.offset,
             fmt=args.format)
    sys.exit(0 if ok else 1)
Beispiel #5
0
 def testSimple(self):
     text = "Hello World!!  This is a test_data"
     v = verse.Verse(text, template.Template(), plint.pattern.Pattern("12"))
     v.parse()
     self.assertEqual(text, v.line)
Beispiel #6
0
 def testLeadingSpaceHyphenConsonant(self):
     text = " -c"
     v = verse.Verse(text, template.Template(), plint.pattern.Pattern("12"))
     v.parse()
     self.assertEqual(text, v.line)
Beispiel #7
0
 def testComplex(self):
     text = "Aye AYAYE   aye  gue que geque AYAYAY a prt   sncf bbbéé"
     v = verse.Verse(text, template.Template(), plint.pattern.Pattern("12"))
     v.parse()
     self.assertEqual(text, v.line)
Beispiel #8
0
 def runCount(self, text, limit=12, hemistiches=None):
     v = verse.Verse(text, template.Template(), plint.pattern.Pattern(str(limit), hemistiches=hemistiches))
     v.parse()
     return v.possible
Beispiel #9
0
 def testBadAlone(self):
     v = verse.Verse("42", template.Template(), plint.pattern.Pattern("12"))
     v.parse()
     self.assertFalse(v.valid())
Beispiel #10
0
 def testBadAndGood(self):
     v = verse.Verse("bla h42 blah ", template.Template(),
                     plint.pattern.Pattern("12"))
     v.parse()
     self.assertFalse(v.valid())
Beispiel #11
0
 def testSingleHyphens(self):
     t = template.Template("12")
     text = "-"
     t.check(text)
Beispiel #12
0
 def testEliminateOneGue(self):
     text = "gue"
     v = verse.Verse(text, template.Template(), plint.pattern.Pattern("12"))
     v.parse()
     c = ''.join([x.text for x in v.chunks.chunks])
     self.assertFalse("gue" in c)
Beispiel #13
0
 def testBadVowel(self):
     v = verse.Verse("patati patata patata arbrisseau", template.Template(),
                     plint.pattern.Pattern("12"))
     v.parse()
     self.assertFalse(v.valid())
Beispiel #14
0
 def testBadEt(self):
     v = verse.Verse("patati patata patata et avant", template.Template(),
                     plint.pattern.Pattern("12"))
     v.parse()
     self.assertFalse(v.valid())
Beispiel #15
0
 def testGoodMuteE(self):
     v = verse.Verse("patati patata patatue arbrisseau",
                     template.Template(), plint.pattern.Pattern("12"))
     v.parse()
     self.assertTrue(v.valid())
Beispiel #16
0
 def testGoodAspirated(self):
     v = verse.Verse("patati patata patata tata hache", template.Template(),
                     plint.pattern.Pattern("12"))
     v.parse()
     self.assertTrue(v.valid())
Beispiel #17
0
 def testBadUnaspirated(self):
     v = verse.Verse("patati patata patata hirondelle", template.Template(),
                     plint.pattern.Pattern("12"))
     v.parse()
     self.assertFalse(v.valid())