def test_jaggedarray_fields(self): j = JaggedArrayNode() j.add_title("title1", "en", primary=True)\ .add_title("ייי", "he", primary=True)\ .add_title("title2", "en")\ .add_title("ייכי", "he") j.depth = 1 j.sectionNames = ["Foo"] j.addressTypes = ["Integer"] j.key = "bob" j.validate() for f in ["depth", "sectionNames", "addressTypes", "key"]: t = copy.deepcopy(j) delattr(t, f) with pytest.raises(IndexSchemaError): t.validate() t = copy.deepcopy(j) t.sectionNames += ["foob"] with pytest.raises(IndexSchemaError): t.validate() t = copy.deepcopy(j) t.addressTypes += ["Integer"] with pytest.raises(IndexSchemaError): t.validate()
def test_default_chain(self): s = SchemaNode() s.key = "root" s.add_title("root", "en", primary=True) s.add_title("alt root", "en") s2 = SchemaNode() s2.key = "default" s2.default = True s2.append_to(s) j = JaggedArrayNode() j.key = "default" j.depth = 1 j.default = True j.sectionNames = ["Foo"] j.addressTypes = ["Integer"] j.append_to(s2) s.validate() assert s.has_numeric_continuation() assert s2.has_numeric_continuation() assert j.has_numeric_continuation() assert not s.has_titled_continuation() assert not s2.has_titled_continuation() assert not j.has_titled_continuation()
def create_shorash_node(): shorash = JaggedArrayNode() shorash.add_title('Shorashim', 'en', primary=True) shorash.add_title(u'שורשים', 'he', primary=True) shorash.key = 'Shorashim' shorash.depth = 2 shorash.addressTypes = ["Integer", "Integer"] shorash.sectionNames = ["Shoresh", "Comment"] return shorash
def create_intro_node(): intro = JaggedArrayNode() intro.add_title('Introduction', 'en', primary=True) intro.add_title(u'הקדמה', 'he', primary=True) intro.key = 'Introduction' intro.depth = 1 intro.addressTypes = ["Integer"] intro.sectionNames = ["Comment"] return intro
def create_shorash_node(): intro_node = JaggedArrayNode() intro_node.add_title('Shorashim', "en", primary=True) intro_node.add_title(u'שורשים', "he", primary=True) intro_node.key = 'Shorashim' intro_node.depth = 2 intro_node.addressTypes = ["Integer", "Integer"] intro_node.sectionNames = ["Shorash", "Comment"] return intro_node
def create_schema(): rb_schema = JaggedArrayNode() rb_schema.add_title('Rabbeinu Yonah on Pirkei Avot', 'en', primary=True) rb_schema.add_title(u'רבינו יונה על פרקי אבות', 'he', primary=True) rb_schema.key = 'Rabbeinu Yonah on Pirkei Avot' rb_schema.depth = 3 rb_schema.addressTypes = ["Integer", "Integer", "Integer"] rb_schema.sectionNames = ["Perek", "Mishna", "Comment"] return rb_schema
def create_positive_commandments_node(): positive_commandments = JaggedArrayNode() positive_commandments.add_title('Positive Commandments', 'en', primary=True) positive_commandments.add_title(u'מנין עשה', 'he', primary=True) positive_commandments.key = 'Positive Commandments' positive_commandments.depth = 2 positive_commandments.addressTypes = ["Integer", "Integer"] positive_commandments.sectionNames = ["Mitzvah", "Comment"] return positive_commandments
def create_intro_nodes(): intro_node = JaggedArrayNode() intro_node.add_title('Introduction', "en", primary=True) intro_node.add_title(u'הצעה', "he", primary=True) intro_node.key = 'Introduction' intro_node.depth = 1 intro_node.addressTypes = ["Integer"] intro_node.sectionNames = ["Comment"] return intro_node
def create_negative_commandments_node(): negative_commandments = JaggedArrayNode() negative_commandments.add_title('Negative Commandments', 'en', primary=True) negative_commandments.add_title(u'מנין לא תעשה', 'he', primary=True) negative_commandments.key = 'Negative Commandments' negative_commandments.depth = 2 negative_commandments.addressTypes = ["Integer", "Integer"] negative_commandments.sectionNames = ["Mitzvah", "Comment"] return negative_commandments
def create_schema(): rif_on_megillah = JaggedArrayNode() rif_on_megillah.add_title('Rif_Megillah', 'en', primary=True) rif_on_megillah.add_title(u'רי"ף מגילה', 'he', primary=True) rif_on_megillah.key = 'Rif_Megillah' rif_on_megillah.depth = 2 rif_on_megillah.addressTypes = ["Talmud", "Integer"] rif_on_megillah.sectionNames = ["Daf", "Line"] return rif_on_megillah
def create_schema(): ls_schema = JaggedArrayNode() ls_schema.add_title('Lechem Shamayim on Pirkei Avot', 'en', primary=True) ls_schema.add_title(u'לחם שמים על פרקי אבות', 'he', primary=True) ls_schema.key = 'Lechem Shamayim on Pirkei Avot' ls_schema.depth = 3 ls_schema.addressTypes = ["Integer", "Integer", "Integer"] ls_schema.sectionNames = ["Perek", "Mishna", "Comment"] return ls_schema
def create_toalot_node(): toalot = JaggedArrayNode() toalot.add_title('Benefits', "en", primary=True) toalot.add_title(u'תועלות', "he", primary=True) toalot.key = 'Benefits' toalot.depth = 1 toalot.addressTypes = ["Integer"] toalot.sectionNames = ["Comment"] return toalot
def regular_chapter_nodes(number): hebrew_letter = util.numToHeb(number) chapter = JaggedArrayNode() chapter.add_title('Chapter {}'.format(number), "en", primary=True) chapter.add_title(u'{} {}'.format(u'סימן',hebrew_letter), "he", primary=True) chapter.key = 'Chapter {}'.format(number) chapter.depth = 1 chapter.addressTypes = ["Integer"] chapter.sectionNames = ["Comment"] return chapter
def chapter_nine(number): hebrew_letter = util.numToHeb(number) chapter = JaggedArrayNode() chapter.add_title('Chapter {}'.format(number), "en", primary=True) chapter.add_title(u'{} {}'.format(u'סימן', hebrew_letter), "he", primary=True) chapter.key = 'Chapter {}'.format(number) chapter.depth = 2 chapter.addressTypes = ["Integer", "Integer"] chapter.sectionNames = ["Section", "Mitzvah"] return chapter
def test_duplicate_primary(self): with pytest.raises(IndexSchemaError): j = JaggedArrayNode() j.add_title("title1", "en", primary=True) j.add_title("title2", "en", primary=True) with pytest.raises(IndexSchemaError): j = JaggedArrayNode() j.add_title("ייי", "he", primary=True) j.add_title("ייעי", "he", primary=True)
def test_jaggedarray_fields(self): j = JaggedArrayNode() j.add_title(u"title1", "en", primary=True)\ .add_title(u"ייי", "he", primary=True)\ .add_title(u"title2", "en")\ .add_title(u"ייכי", "he") j.depth = 1 j.sectionNames = ["Foo"] j.addressTypes = ["Integer"] j.key = "bob" j.validate() for f in ["depth", "sectionNames", "addressTypes", "key"]: t = copy.deepcopy(j) delattr(t, f) with pytest.raises(IndexSchemaError): t.validate() t = copy.deepcopy(j) t.sectionNames += ["foob"] with pytest.raises(IndexSchemaError): t.validate() t = copy.deepcopy(j) t.addressTypes += ["Integer"] with pytest.raises(IndexSchemaError): t.validate()
def build_index(self, base_title, he_base_title): """ Builds the root schema node for the commentary :return: serialized index """ node = JaggedArrayNode() he_author = self.get_author() en_author = commentatorNames[he_author] node.add_primary_titles('{} on {}'.format(en_author, base_title), u'{} על {}'.format(he_author, he_base_title)) node.add_structure(['Chapter', 'Halakhah', 'Comment']) node.validate() return { 'title': '{} on {}'.format(en_author, base_title), 'categories': ['Tanaitic', 'Commentary', en_author, "Masechtot Ketanot"], 'schema': node.serialize(), 'collective_title': en_author, 'dependence': "Commentary", 'base_text_titles': [base_title] }
def get_base_index(en_title, he_title): node = JaggedArrayNode() node.add_primary_titles(en_title, he_title) node.add_structure(['Chapter', 'Halakhah']) node.validate() return { 'title': en_title, 'categories': ["Tanaitic", "Masechtot Ketanot"], 'schema': node.serialize() }
def create_book_ja_node(english_book_name, hebrew_book_name): en_name = english_book_name[0] he_name = hebrew_book_name[0] book_node = JaggedArrayNode() book_node.key = en_name book_node.add_title(en_name, 'en', primary=True) book_node.add_title(he_name, 'he', primary=True) book_node.depth = 3 book_node.addressTypes = ["Integer", "Integer", "Integer"] book_node.sectionNames = ["Chapter", "Verse", "Comment"] book_node.toc_zoom = 2 return book_node
def create_jagged_array_nodes(en_name, he_name): book_node = JaggedArrayNode() book_node.key = en_name book_node.add_title(en_name, 'en', primary=True) book_node.add_title(he_name, 'he', primary=True) book_node.depth = 2 book_node.addressTypes = ["Integer", "Integer"] book_node.sectionNames = ["Chapter", "Verse"] return book_node
def create_commentary_node(): commentary = JaggedArrayNode() commentary.default = True commentary.key = 'default' commentary.depth = 3 commentary.addressTypes = ["Integer", "Integer", "Integer"] commentary.sectionNames = ["Perek", "Pasuk", "Comment"] commentary.toc_zoom = 2 return commentary
def create_schema(): rif_on_nedarim = JaggedArrayNode() rif_on_nedarim.add_title('Rif_Nedarim', 'en', primary=True) rif_on_nedarim.add_title(u'רי"ף נדרים', 'he', primary=True) rif_on_nedarim.key = 'Rif_Nedarim' rif_on_nedarim.depth = 2 rif_on_nedarim.addressTypes = ["Talmud", "Integer"] rif_on_nedarim.sectionNames = ["Daf", "Line"] return rif_on_nedarim
def create_schema(): gra_schema = JaggedArrayNode() gra_schema.add_title('Gra on Pirkei Avot', 'en', primary=True) gra_schema.add_title(u'גר"א על פרקי אבות', 'he', primary=True) gra_schema.key = 'Gra on Pirkei Avot' gra_schema.depth = 3 gra_schema.addressTypes = ["Integer", "Integer", "Integer"] gra_schema.sectionNames = ["Perek", "Mishna", "Comment"] return gra_schema
def create_mitzvah_node(en_name, he_name): mitzvah = JaggedArrayNode() mitzvah.add_title(en_name, 'en', primary=True) mitzvah.add_title(he_name, 'he', primary=True) mitzvah.key = en_name mitzvah.depth = 2 mitzvah.addressTypes = ["Integer", "Integer"] mitzvah.sectionNames = ["Mitzvah", "Comment"] return mitzvah
def test_duplicate_primary(self): with pytest.raises(IndexSchemaError): j = JaggedArrayNode() j.add_title(u"title1", "en", primary=True) j.add_title(u"title2", "en", primary=True) with pytest.raises(IndexSchemaError): j = JaggedArrayNode() j.add_title(u"ייי", "he", primary=True) j.add_title(u"ייעי", "he", primary=True)
def get_base_index(en_title, he_title): node = JaggedArrayNode() node.add_primary_titles(en_title, he_title) node.add_structure(['Chapter', 'Halakhah']) node.validate() return { 'title': en_title, 'categories': ["Masechtot Ketanot"], 'schema': node.serialize() }
def create_default_nodes(): default = JaggedArrayNode() default.default = True default.key = 'default' default.depth = 2 default.addressTypes = ["Integer", "Integer"] default.sectionNames = ["Mitzvah", "Comment"] return default
def create_default_nodes(): default_node = JaggedArrayNode() default_node.key = 'default' default_node.default = True default_node.depth = 1 default_node.addressTypes = ["Integer"] default_node.sectionNames = ["Comment"] return default_node
def create_jagged_array_node(): jagged_array_node = JaggedArrayNode() jagged_array_node.key = 'default' jagged_array_node.default = True jagged_array_node.depth = 1 jagged_array_node.addressTypes = ["Integer"] jagged_array_node.sectionNames = ["Comment"] return jagged_array_node
def test_validate_children(self): """ Does validate fall through to children? """ s = SchemaNode() s.key = "root" s.add_title("root", "en", primary=True) j = JaggedArrayNode() j.add_title("child", "en", primary=True) j.key = "child" j.depth = 1 j.sectionNames = ["Foo"] j.append_to(s) with pytest.raises(IndexSchemaError): s.validate()
def create_default_nodes(): default_node = JaggedArrayNode() default_node.key = "default" default_node.default = True default_node.depth = 1 default_node.addressTypes = ["Integer"] default_node.sectionNames = ["Comment"] return default_node
def commentary_ja_node(en_title, he_title): """ Each commentary is a complex text, with a root schema and depth 3 JAnodes for each tractate. The JAnode for each tractate is essentially identical across commentaries. The root schema is what defines the particular commentator. Deprecated - schema system has changed. :param en_title: English Title of base text :param he_title: Hebrew Title of base text :return: JaggedArrayNode """ raise NotImplementedError("Don't use me!") node = JaggedArrayNode() node.add_primary_titles(en_title, he_title) node.add_structure(['Chapter', 'Halakhah', 'Comment']) node.validate() return node
def commentary_ja_node(en_title, he_title): """ Each commentary is a complex text, with a root schema and depth 3 JAnodes for each tractate. The JAnode for each tractate is essentially identical across commentaries. The root schema is what defines the particular commentator. :param en_title: English Title of base text :param he_title: Hebrew Title of base text :return: JaggedArrayNode """ node = JaggedArrayNode() node.add_primary_titles(en_title, he_title) node.add_structure(['Chapter', 'Halakhah', 'Comment']) node.validate() return node
def test_terms_and_he(self): s = SchemaNode() s.key = "root" s.add_title("root", "en", primary=True) s.add_title("שרש", "he", primary=True) j = JaggedArrayNode() j.key = "bereshit" j.depth = 1 j.sectionNames = ["Foo"] j.addressTypes = ["Integer"] j.add_shared_term("Bereshit") j.append_to(s) j2 = JaggedArrayNode() j2.key = "noah" j2.depth = 1 j2.sectionNames = ["Foo"] j2.addressTypes = ["Integer"] j2.add_shared_term("Noach") j2.append_to(s) s.validate() td = s.title_dict("he") assert len(td) == 5 target = { 'שרש': s, 'שרש, בראשית': j, 'שרש, נח': j2, 'שרש בראשית': j, 'שרש נח': j2, } assert td == target
def test_remove(self): j = JaggedArrayNode() j.add_title("title1", "en", primary=True)\ .add_title("ייי", "he", primary=True)\ .add_title("title2", "en")\ .add_title("ייכי", "he") j.remove_title("title1", "en") j.depth = 1 j.sectionNames = ["Foo"] j.addressTypes = ["Integer"] j.key = "bob" with pytest.raises(IndexSchemaError): j.validate()
def test_add(self): j = JaggedArrayNode() j.add_title("title1", "en", primary=True) j.add_title("ייי", "he", primary=True) j.add_title("title2", "en") j.add_title("ייכי", "he") assert len(j.all_node_titles("he")) == 2 assert len(j.all_node_titles("en")) == 2 assert j.primary_title("en") == "title1" j.add_title("title3", "en", primary=True, replace_primary=True) assert len(j.all_node_titles("en")) == 3 assert len(j.all_node_titles("he")) == 2 assert j.primary_title("en") == "title3"
def post_yitzira(): node = JaggedArrayNode() node.add_title('Sefer Yetzirah', 'en', primary=True) node.add_title(u'ספר יצירה', 'he', primary=True) node.key = 'Sefer Yetzirah' node.depth = 2 node.addressTypes = ['Integer', 'Integer'] node.sectionNames = ['Chapter', 'Mishnah'] node.validate() y_index = { 'title': 'Sefer Yetzirah', 'categories': ['Kabbalah'], 'language': 'he', 'schema': node.serialize() } y_version = { 'versionTitle': 'Sefer Yetzirah, Warsaw 1884', 'versionSource': 'http://primo.nli.org.il/primo_library/libweb/action/dlDisplay.do?vid=NLI&docId=NNL_ALEPH001310968', 'language': 'he', 'text': parse_yitzira() } post_index(y_index) post_text("Sefer Yetzirah", y_version, index_count='on')
def post_simple_commentaries(): ramban_node, rasag_node = JaggedArrayNode(), JaggedArrayNode() ramban_text = parse_general('yitzira_ramban.txt') rasag_text = parse_general('yitzira_rasag.txt') ramban_node.add_title("Ramban on Sefer Yetzirah", 'en', primary=True) ramban_node.add_title(u'רמב"ן על ספר יצירה', 'he', primary=True) ramban_node.key = "Ramban on Sefer Yetzirah" ramban_node.addressTypes = ['Integer', 'Integer', 'Integer'] ramban_node.sectionNames = ["Chapter", "Mishnah", "Comment"] ramban_node.toc_zoom = 2 ramban_node.depth = 3 ramban_node.validate() rasag_node.add_title("Rasag on Sefer Yetzirah", 'en', primary=True) rasag_node.add_title(u'רס"ג על ספר יצירה', 'he', primary=True) rasag_node.key = "Rasag on Sefer Yetzirah" rasag_node.addressTypes = ['Integer', 'Integer', 'Integer'] rasag_node.sectionNames = ["Chapter", "Mishnah", "Comment"] rasag_node.toc_zoom = 2 rasag_node.depth = 3 rasag_node.validate() ramban_index = { "title": "Ramban on Sefer Yetzirah", "categories": ["Commentary2", "Kabbalah", "Ramban"], "language": "he", "schema": ramban_node.serialize() } post_index(ramban_index) post_text("Ramban on Sefer Yetzirah", { 'versionTitle': 'Ramban on Sefer Yetzirah, Warsaw 1884', 'versionSource': 'http://primo.nli.org.il/primo_library/libweb/action/dlDisplay.do?vid=NLI&docId=NNL_ALEPH001310968', 'language': 'he', 'text': ramban_text }) rasag_index = { "title": "Rasag on Sefer Yetzirah", "categories": ["Commentary2", "Kabbalah", "Rasag"], "language": "he", "schema": rasag_node.serialize() } post_index(rasag_index) post_text("Rasag on Sefer Yetzirah", { 'versionTitle': 'Rasage on Sefer Yetzirah, Warsaw 1884', 'versionSource': 'http://primo.nli.org.il/primo_library/libweb/action/dlDisplay.do?vid=NLI&docId=NNL_ALEPH001310968', 'language': 'he', 'text': rasag_text }) links = linker(ramban_text, "Ramban on Sefer Yetzirah") links.extend(linker(rasag_text, "Rasag on Sefer Yetzirah")) post_link(links)
def build_index(titles): struct_node = JaggedArrayNode() struct_node.add_title('Sefer HaKana', 'en', primary=True) struct_node.add_title(u'ספר הקנה', 'he', primary=True) struct_node.key = 'Sefer HaKana' struct_node.depth = 2 struct_node.addressTypes = ['Integer', 'Integer'] struct_node.sectionNames = ['Chapter', 'Comment'] struct_node.add_title('Sefer HaQana', 'en') struct_node.add_title('Sefer HaQanah', 'en') struct_node.add_title('Sefer Hakana', 'en') struct_node.add_title('Sefer HaKanah', 'en') struct_node.validate() alt_struct = TitledTreeNode() for index, title in enumerate(titles): i = index + 1 node = ArrayMapNode() node.add_title('Chapter {}'.format(i), 'en', primary=True) node.add_title(title.replace(u'ד"ה ', u''), 'he', primary=True) node.depth = 0 node.wholeRef = 'Sefer HaKana {}'.format(i) alt_struct.append(node) return { 'title': 'Sefer HaKana', 'categories': ['Kabbalah'], 'schema': struct_node.serialize(), 'alt_structs': {'Titles': alt_struct.serialize()} }