def testIngredient1(self): s = "Es wird hierzu für 24—30 Personen eine kräftige Bouillon von 8—10 Pfund Rindfleisch mit Wurzelwerk gekocht." wordProperties = dictBasedEnrichment(s, self.ingE, self.unitE) self.assertIsNotNone(wordProperties[8].properties.get( WordProperty.INGREDIENT)) self.assertEqual( 0, len(wordProperties[8].properties.get(WordProperty.INGREDIENT)))
def test2(self): s = "Der Soja macht die Suppe gewürzreicher, kann jedoch gut wegbleiben, und \ statt Madeira kann man weißen Franzwein nehmen, desweiteren Rum rein tun" wordProperties = dictBasedEnrichment(s, self.ingE, self.unitE) wordProperties = altGrpRule(wordProperties, None) self.assertEqual("1", wordProperties[14].properties.get(WordProperty.ALT_GRP)) self.assertEqual("2", wordProperties[18].properties.get(WordProperty.ALT_GRP)) self.assertIsNone(wordProperties[22].properties.get(WordProperty.ALT_GRP))
def testWP0(self): s = "Es wird hierzu für 24—30 Personen eine kräftige Bouillon von 8—10 Pfund Rindfleisch mit Wurzelwerk gekocht." wordProperties = dictBasedEnrichment(s, self.ingE, self.unitE) self.assertIsNone(wordProperties[0].properties.get( WordProperty.INGREDIENT)) self.assertIsNone(wordProperties[0].properties.get(WordProperty.UNIT)) self.assertIsNone(wordProperties[0].properties.get( WordProperty.QUANTITY))
def testFleisch(self): wordProperties = dictBasedEnrichment("Fleisch", self.ingE, self.unitE) rcp = PlainTextRecipe("", "Suppen", "Rindfleischsuppe", "") wordProperties = dissolveAmbiguityRule(wordProperties, rcp) dissolvedCandis = wordProperties[0].properties.get( WordProperty.INGREDIENT) self.assertEqual(1, len(dissolvedCandis)) self.assertEqual("Rindkochfleisch", dissolvedCandis[0].xmlID)
def testIngredient1(self): s = " Es wird dies Alles ohne Ei und Salz in einem tiefen Topf auf sehr starkem Feuer bis vor dem Kochen ohne Aufhören stark gerührt." wordProperties = dictBasedEnrichment(s, self.ingE, self.unitE) self.assertIsNotNone( wordProperties[5].properties.get(WordProperty.INGREDIENT), "dictbasedEnrichment is already broken") wordProperties = dontUseRule(wordProperties, None) self.assertIsNone(wordProperties[5].properties.get( WordProperty.INGREDIENT))
def testIngredient2(self): s = "Es wird hierzu für 24—30 Personen eine kräftige Bouillon von 8—10 Pfund Rindfleisch mit Wurzelwerk gekocht." wordProperties = dictBasedEnrichment(s, self.ingE, self.unitE) self.assertIsNotNone(wordProperties[12].properties.get( WordProperty.INGREDIENT)) self.assertIn("Rindkochfleisch", [ candi.xmlID for candi in wordProperties[12].properties.get( WordProperty.INGREDIENT) ])
def extractSentence(self, sentence, rcp): xmlStrings = [] wps = dictBasedEnrichment(sentence, self.ingE, self.unitE) improvedWps = applyRulesToWordProperties(wps, rcp) for wp in improvedWps: if wp.lemma not in string.punctuation: xmlStrings.append(" ") xmlStrings.append(wp.toXml(self.cueMLPrefix)) return "".join(xmlStrings)
def test1(self): s = "Der Soja macht die Suppe gewürzreicher, kann jedoch gut wegbleiben, und \ statt Madeira kann man weißen Franzwein und etwas Rum nehmen" wordProperties = dictBasedEnrichment(s, self.ingE, self.unitE) self.assertIsNotNone( wordProperties[1].properties.get(WordProperty.INGREDIENT), "dictbasedEnrichment is already broken") wordProperties = optionalRule(wordProperties, None) self.assertTrue(wordProperties[1].properties.get( WordProperty.OPTIONAL))
def testIngredient3(self): s = "Es wird hierzu für 24—30 Personen eine kräftige Bouillon von 8—10 Pfund Rindfleisch mit Wurzelwerk gekocht." wordProperties = dictBasedEnrichment(s, self.ingE, self.unitE) wordProperties = findQuantityAndUnitOfIngredientRule( wordProperties, None) self.assertIsNotNone(wordProperties[14].properties.get( WordProperty.INGREDIENT)) self.assertIsNone(wordProperties[14].properties.get(WordProperty.UNIT)) self.assertIsNone(wordProperties[14].properties.get( WordProperty.QUANTITY))
def testWein(self): s = "Zwei Eßlöffel voll Mehl werden mit einem Stich frischer Butter dunkelgelb geschwitzt,\ mit Zungenbrühe abgerührt, dazu Rosinen, rother Wein, Zitronensaft und Schale,\ Muskatblüthe, etwas Zucker und Salz." wordProperties = dictBasedEnrichment(s, self.ingE, self.unitE) wordProperties = dissolveAmbiguityRule(wordProperties, None) dissolvedCandis = wordProperties[21].properties.get( WordProperty.INGREDIENT) self.assertEqual(1, len(dissolvedCandis)) self.assertEqual("Rotwein", dissolvedCandis[0].xmlID)
def myPlaygroundTest(): """Just a random test function for me""" rcp = PlainTextRecipe("B-16", "Suppen", "Mock Turtle Suppe", [ "Sowohl die Bouillon als \ Kalbskopf können schon am vorhergehenden Tage, ohne Nachtheil der Suppe, gekocht werden." ]) extractor = Extractor(ingE, unitE) print(extractor.extractRecipe(rcp)) s = "Schweinemagen" print(ingE.__ingDict__["Schweinemagen"]) wps = dictBasedEnrichment(s, ingE, unitE) wps = applyRulesToWordProperties(wps, None) for wp in wps: print(wp)
def testAbbrühen(self): s = "Das Fleisch abbrühen." wordProperties = dictBasedEnrichment(s, self.ingE, self.unitE) self.assertIsNone(wordProperties[2].properties.get( WordProperty.INGREDIENT))
def testQuantity2(self): s = "Es wird hierzu für 24—30 Personen eine kräftige Bouillon von 8—10 Pfund Rindfleisch mit Wurzelwerk gekocht." wordProperties = dictBasedEnrichment(s, self.ingE, self.unitE) self.assertEqual( "8—10", wordProperties[10].properties.get(WordProperty.QUANTITY))