diff --git a/fetchhtml.go b/fetchhtml.go new file mode 100644 index 0000000..bd59e80 --- /dev/null +++ b/fetchhtml.go @@ -0,0 +1,83 @@ +package main + +import( + "log" + "net/http" + "github.com/PuerkitoBio/goquery" + "strconv" + "strings" +) +type chapter struct{ + verses []string +} + +type book struct{ + chapters []chapter +} + +func fetchChapter(book, searchedChapter, version string) (chapter, error){ + + url := "https://www.biblegateway.com/passage/?search=" + book + "%20" + searchedChapter +"&version=" + version + + res, err := http.Get(url) + if err != nil { + log.Printf("can’t get %s : %v\n", url, err) + return chapter{}, err + } + + defer res.Body.Close() + if res.StatusCode != http.StatusOK { + log.Printf("error code %v: %v\n", res.StatusCode, res.Status) + return chapter{}, err + } + + doc, err := goquery.NewDocumentFromReader(res.Body) + if err != nil { + log.Printf("error reading the http response: %v\n", err) + return chapter{}, err + } + + chapterText := chapter{} + replacer := strings.NewReplacer( + "L'Éternel", "YAHWEH", + "l'Éternel", "YAHWEH", + "Éternel", "YAHWEH", + ) + + doc.Find(".verse > span").Each(func(i int, s *goquery.Selection){ + /**********************************************************************************/ + /**** verses are marked by an .verse class. Inside the text is in a span and *****/ + /**** begin either by the chapter number (first verse), or by the verse *****/ + /**** (the other verses). With that the code is straight forward. *****/ + /**********************************************************************************/ + rawText := s.Text() + verse:= "" + if i == 0 { + verse, _ = strings.CutPrefix(rawText, searchedChapter ) + }else{ + + verse, _ = strings.CutPrefix(rawText, strconv.Itoa(i+1)) + } + verse = replacer.Replace(verse) + chapterText.verses = append(chapterText.verses, strings.TrimSpace(verse)) + }) + + return chapterText, nil +} + +/* +func fecthBook (book, version string, chapterNumbers int) book, error{ + failedChapter := 0 + bookChapters := book{} + + for i:= 1 ; i > chapterNumbers ; i++{ + verses, err := fetchChapter(book, strconv.Itoa(i), version) + if err != nil { + failedChapter++ + log.Printf("%s", err) + continue + } + book.chapters = append(book, + +} +*/ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..a0cfa83 --- /dev/null +++ b/go.mod @@ -0,0 +1,9 @@ +module project.hechon.fr + +go 1.25.4 + +require ( + github.com/PuerkitoBio/goquery v1.11.0 // indirect + github.com/andybalholm/cascadia v1.3.3 // indirect + golang.org/x/net v0.47.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..806bd54 --- /dev/null +++ b/go.sum @@ -0,0 +1,71 @@ +github.com/PuerkitoBio/goquery v1.11.0 h1:jZ7pwMQXIITcUXNH83LLk+txlaEy6NVOfTuP43xxfqw= +github.com/PuerkitoBio/goquery v1.11.0/go.mod h1:wQHgxUOU3JGuj3oD/QFfxUdlzW6xPHfqyHre6VMY4DQ= +github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM= +github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= +golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= +golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY= +golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= +golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= +golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= +golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/main.go b/main.go new file mode 100644 index 0000000..f7cb3cc --- /dev/null +++ b/main.go @@ -0,0 +1,48 @@ +package main + +import( + "log" + "os" + "strings" +) + +func loadExclude(path string) (map[string]struct{}, error) { + b, err := os.ReadFile(path) + if err != nil { return nil, err } + m := make(map[string]struct{}) + for _, line := range strings.Split(string(b), "\n") { + w := strings.TrimSpace(line) + if w == "" || strings.HasPrefix(w, "#") { continue } + m[w] = struct{}{} + } + return m, nil +} + +func main (){ + + properName, err:= loadExclude("properName.txt") + if err != nil{ + log.Printf("can’t open the proper names file") + os.Exit(1) + } + book := "Psaumes" + searchedChapter := "2" + version := "LSG" + + Chapter, err := fetchChapter(book, searchedChapter, version) + + if err != nil { + log.Printf("GET %s %s %s failed\n", book, searchedChapter, version) + os.Exit(1) + } + + Chapter = stripAlternativeVersification(Chapter) + + for i, verse := range Chapter.verses{ + log.Printf("==== Verse: %v ====", i+1) + splitInPart(verse, properName) + } + + os.Exit(0) +} + diff --git a/properName.txt b/properName.txt new file mode 100644 index 0000000..64df827 --- /dev/null +++ b/properName.txt @@ -0,0 +1,72 @@ +Aaron +Abraham +Adam +Amalek +Ammon +Amoréens +Babylone +Baal +Benjamin +Basan +Cham +David +Dathan +Dieu +Dor +Ephraïm +Édom +Égypte +Égyptiens +Éphrata +Galaad +Guébal +Hagaréniens +Hermon +Horeb +Isaac +Ismaëlites +Israël +Jacob +Jabin +Jerusalem +Joseph +Juda +Liban +Lévi +Manassé +Madian +Massa +Melchisedek +Mitsear +Mériba +Moab +Moïse +Néphtali +Oreb +Og +Pharaon +Philistins +Peor +Phinéas +Rouge +Saba +Salem +Seba +Sichem +Sirion +Sisera +Sihon +Silo +Sinaï +Seigneur +Sion +Succoth +Tarsis +Thabor +Tsalmon +Tsalmunna +Tyr +YAHWEH +Zabulon +Zébach +Zeeb diff --git a/ps69.txt b/ps69.txt new file mode 100644 index 0000000..432198f --- /dev/null +++ b/ps69.txt @@ -0,0 +1,36 @@ +"Au chef des chantres. Sur les lis. De David. Sauve-moi, ô Dieu! Car les eaux menacent ma vie." +"J'enfonce dans la boue, sans pouvoir me tenir; Je suis tombé dans un gouffre, et les eaux m'inondent." +"Je m'épuise à crier, mon gosier se dessèche, Mes yeux se consument, tandis que je regarde vers mon Dieu." +"Ils sont plus nombreux que les cheveux de ma tête, Ceux qui me haïssent sans cause; Ils sont puissants, ceux qui veulent me perdre, Qui sont à tort mes ennemis. Ce que je n'ai pas dérobé, il faut que je le restitue." +"O Dieu! tu connais ma folie, Et mes fautes ne te sont point cachées." +"Que ceux qui espèrent en toi ne soient pas confus à cause de moi, Seigneur, YAHWEH des armées! Que ceux qui te cherchent ne soient pas dans la honte à cause de moi, Dieu d'Israël!" +"Car c'est pour toi que je porte l'opprobre, Que la honte couvre mon visage;" +"Je suis devenu un étranger pour mes frères, Un inconnu pour les fils de ma mère." +"Car le zèle de ta maison me dévore, Et les outrages de ceux qui t'insultent tombent sur moi." +"Je verse des larmes et je jeûne, Et c'est ce qui m'attire l'opprobre;" +"Je prends un sac pour vêtement, Et je suis l'objet de leurs sarcasmes." +"Ceux qui sont assis à la porte parlent de moi, Et les buveurs de liqueurs fortes me mettent en chansons." +"Mais je t'adresse ma prière, ô YAHWEH! Que ce soit le temps favorable, ô Dieu, par ta grande bonté! Réponds-moi, en m'assurant ton secours!" +"Retire-moi de la boue, et que je n'enfonce plus! Que je sois délivré de mes ennemis et du gouffre!" +"Que les flots ne m'inondent plus, Que l'abîme ne m'engloutisse pas, Et que la fosse ne se ferme pas sur moi!" +"Exauce-moi, YAHWEH! car ta bonté est immense. Dans tes grandes compassions, tourne vers moi les regards," +"Et ne cache pas ta face à ton serviteur! Puisque je suis dans la détresse, hâte-toi de m'exaucer!" +"Approche-toi de mon âme, délivre-la! Sauve-moi, à cause de mes ennemis!" +"Tu connais mon opprobre, ma honte, mon ignominie; Tous mes adversaires sont devant toi." +"L'opprobre me brise le coeur, et je suis malade; J'attends de la pitié, mais en vain, Des consolateurs, et je n'en trouve aucun." +"Ils mettent du fiel dans ma nourriture, Et, pour apaiser ma soif, ils m'abreuvent de vinaigre." +"Que leur table soit pour eux un piège, Et un filet au sein de leur sécurité!" +"Que leurs yeux s'obscurcissent et ne voient plus, Et fais continuellement chanceler leurs reins!" +"Répands sur eux ta colère, Et que ton ardente fureur les atteigne!" +"Que leur demeure soit dévastée, Qu'il n'y ait plus d'habitants dans leurs tentes!" +"Car ils persécutent celui que tu frappes, Ils racontent les souffrances de ceux que tu blesses." +"Ajoute des iniquités à leurs iniquités, Et qu'ils n'aient point part à ta miséricorde!" +"Qu'ils soient effacés du livre de vie, Et qu'ils ne soient point inscrits avec les justes!" +"Moi, je suis malheureux et souffrant: O Dieu, que ton secours me relève!" +"Je célébrerai le nom de Dieu par des cantiques, Je l'exalterai par des louanges." +"Cela est agréable à YAHWEH, plus qu'un taureau Avec des cornes et des sabots." +"Les malheureux le voient et se réjouissent; Vous qui cherchez Dieu, que votre coeur vive!" +"Car YAHWEH écoute les pauvres, Et il ne méprise point ses captifs." +"Que les cieux et la terre le célèbrent, Les mers et tout ce qui s'y meut!" +"Car Dieu sauvera Sion, et bâtira les villes de Juda; On s'y établira, et l'on en prendra possession;" +"La postérité de ses serviteurs en fera son héritage, Et ceux qui aiment son nom y auront leur demeure." diff --git a/textmanipulation.go b/textmanipulation.go new file mode 100644 index 0000000..15f8f51 --- /dev/null +++ b/textmanipulation.go @@ -0,0 +1,50 @@ +package main + +import( + "log" + "regexp" + "strings" + "unicode" + "unicode/utf8" +) + +func stripAlternativeVersification(rawChapter chapter) chapter{ + regExp:=regexp.MustCompile(`\(\d+:\d+\)`) + + var treatedChapter chapter + for _, verse := range rawChapter.verses{ + modifiedVerse := string(regExp.ReplaceAll([]byte(verse), []byte(""))) + log.Printf("%v\n", modifiedVerse) + treatedChapter.verses = append(treatedChapter.verses, modifiedVerse) + } + + return treatedChapter +} + +func splitInPart(verse string, properName map[string]struct{})(){ + + currentPart := "" + words := strings.Split(strings.TrimSpace(verse), " ") + wordsCount := len(words) + isTreated := false + + for i :=0 ; i < wordsCount ; i++{ + word := words[i] + r, _ := utf8.DecodeRuneInString(word) + trimedWord := strings.TrimRight(word, ".,") + _, isProperName := properName[trimedWord] + if i != 0 && unicode.IsUpper(r) && !isProperName{ + log.Printf("%s", currentPart) + currentPart = word + isTreated = true + }else{ + currentPart += " " + word + isTreated = false + } + } + + if !isTreated { + log.Printf("%s", currentPart) + } + +}