def test_rebuild_same_quantity_of_links_for_many_to_one_default_only(self): title = "Rashi on Deuteronomy" base = "Deuteronomy" rf = Ref(title) linker = rf.autolinker() # prepare the text for the tests: # convert simple text to a complex text with default node and add base_text_* and dependence properties. index = library.get_index(title) convert_simple_index_to_complex(index) index.base_text_mapping = "many_to_one_default_only" index.base_text_titles = [base] index.dependence = "Commentary" index.save() # add intro node and give it some text intro = JaggedArrayNode() intro.add_shared_term("Introduction") intro.key = 'intro' intro.add_structure(["Chapter", "Paragraph"]) insert_first_child(intro, library.get_index(title).nodes) comm_ref = "{}, Introduction 1:1".format(title) tc = TextChunk(Ref(comm_ref), vtitle="test", lang="en") tc.text = "Intro first segment text" tc.save() # assert that despite adding text to the intro node, the number of links # should be exactly as they were before (e.g desired_link_count) found = linker.rebuild_links() desired_link_count = self.desired_link_counts[title] assert len(found) == desired_link_count
def test_rebuild_same_quantity_of_links_for_one_to_one_default_only(self): title = "Onkelos Genesis" base = "Genesis" rf = Ref(title) linker = rf.autolinker() # prepare the text for the tests: # convert simple text to a complex text with default node and add base_text_* and dependence properties. index = library.get_index(title) convert_simple_index_to_complex(index) index.base_text_mapping = "one_to_one_default_only" index.base_text_titles = [base] index.dependence = "Commentary" index.save() # add intro node and give it some text intro = JaggedArrayNode() intro.add_shared_term("Introduction") intro.key = 'intro' intro.add_structure(["Chapter", "Paragraph"]) insert_first_child(intro, library.get_index(title).nodes) comm_ref = "{}, Introduction 1:1".format(title) tc = TextChunk(Ref(comm_ref), vtitle="test", lang="en") tc.text = "Intro first segment text" tc.save() # need to change value of "generated_by" from "MatchBaseTextDepthAutoLinker" to "add_commentary_links" # and "link_type" from "targum" to "commentary" for l in LinkSet({ "refs": { "$regex": title }, "generated_by": "MatchBaseTextDepthAutoLinker" }): l.generated_by = linker._generated_by_string l.auto = linker._auto l.type = linker._link_type l.save() # assert that despite adding text to the intro node, the number of links # should be exactly as they were before (e.g desired_link_count) found = linker.rebuild_links() desired_link_count = self.desired_link_counts[title] assert len(found) == desired_link_count
def test_rebuild_same_quantity_of_links_for_one_to_one_default_only(self): title = "Onkelos Genesis" base = "Genesis" rf = Ref(title) linker = rf.autolinker() # prepare the text for the tests: # convert simple text to a complex text with default node and add base_text_* and dependence properties. index = library.get_index(title) convert_simple_index_to_complex(index) index.base_text_mapping = "one_to_one_default_only" index.base_text_titles = [base] index.dependence = "Commentary" index.save() # add intro node and give it some text intro = JaggedArrayNode() intro.add_shared_term("Introduction") intro.key = 'intro' intro.add_structure(["Chapter", "Paragraph"]) insert_first_child(intro, library.get_index(title).nodes) comm_ref = "{}, Introduction 1:1".format(title) tc = TextChunk(Ref(comm_ref), vtitle="test", lang="en") tc.text = "Intro first segment text" tc.save() # need to change value of "generated_by" from "MatchBaseTextDepthAutoLinker" to "add_commentary_links" # and "link_type" from "targum" to "commentary" for l in LinkSet({"refs": {"$regex": title}, "generated_by": "MatchBaseTextDepthAutoLinker"}): l.generated_by = linker._generated_by_string l.auto = linker._auto l.type = linker._link_type l.save() # assert that despite adding text to the intro node, the number of links # should be exactly as they were before (e.g desired_link_count) found = linker.rebuild_links() desired_link_count = self.desired_link_counts[title] assert len(found) == desired_link_count
# -*- coding: utf-8 -*- from sefaria.helper.text import * from sefaria.helper.schema import insert_first_child, convert_simple_index_to_complex i = library.get_index("Sefer HaChinuch") convert_simple_index_to_complex(i) i = library.get_index("Sefer HaChinuch") root = i.nodes n = JaggedArrayNode() n.key = "Opening Letter by the Author" n.add_title("Opening Letter by the Author", "en", primary=True) n.add_title(u"איגרת המחבר", "he", primary=True) n.depth = 1 n.sectionNames = ["Paragraph"] n.addressTypes = ["Integer"] insert_first_child(n, root) n = JaggedArrayNode() n.key = "Author's Introduction" n.add_title("Author's Introduction", "en", primary=True) n.add_title(u"הקדמת המחבר", "he", primary=True) n.depth = 1 n.sectionNames = ["Paragraph"] n.addressTypes = ["Integer"] insert_first_child(n, root)
# -*- coding: utf-8 -*- from sefaria.model import * from sefaria.helper.schema import insert_first_child, convert_simple_index_to_complex, insert_last_child i = library.get_index("Likutei Moharan") convert_simple_index_to_complex(i) i = library.get_index("Likutei Moharan") root = i.nodes hakdama = JaggedArrayNode() shir = JaggedArrayNode() lechu = JaggedArrayNode() tinyana = JaggedArrayNode() letters = JaggedArrayNode() hakdama.key = "Introduction" hakdama.add_title("Introduction", "en", primary=True) hakdama.add_title(u"הקדמה", "he", primary=True) hakdama.depth = 1 hakdama.sectionNames = ["Paragraph"] hakdama.addressTypes = ["Integer"] shir.key = "Shir" shir.add_title("A Pleasant Song", "en", primary=True) shir.add_title(u"שיר נעים", "he", primary=True) shir.depth = 1 shir.sectionNames = ["Line"] shir.addressTypes = ["Integer"]