Я пытаюсь преобразовать мои 2 текстовых столбца в 1.
Я работаю с этим библейским текстом в формате PDF ( исходный ), который извлекаю с помощью pdftools
пакет:
text <- pdf_text("NewKingJamesBible.pdf")
> length(text) #Total number of pages of document
[1] 1815
Это дает мне строку символов с длиной длины файла PDF.Чтобы получить доступ к странице 60 и сохранить ее в текстовом файле (я позже скопирую это в WORD), можно сделать:
fileConn <- file("page_60.txt")
writeLines(text[60], fileConn)
close(fileConn)
Каждый объект внутри text
является страницей.И каждая страница делится на две колонки.Вы читаете сначала левую колонку, а затем правую.
Однако мне нужно иметь весь текст в 1 столбце для каждой страницы.Возможно ли сделать это в R?
Вот как выглядит выходной текст для страницы 60:
16
Then they journeyed from Bethel. And These were the sons of Jacob who were
when there was but a little distance to born to him in Padan Aram.
go to Ephrath, Rachel labored in
childbirth, and she had hard labor. 27
Then Jacob came to his father Isaac at
Mamre, or Kirjath Arba (that is, Hebron),
17
Now it came to pass, when she was in where Abraham and Isaac had dwelt.
hard labor, that the midwife said to her,
"Do not fear; you will have this son 28
Now the days of Isaac were one
also." hundred and eighty years.
18
And so it was, as her soul was 29
So Isaac breathed his last and died,
departing (for she died), that she called and was gathered to his people, being
his name Ben-Oni; but his father called old and full of days. And his sons Esau
him Benjamin. and Jacob buried him.
19
So Rachel died and was buried on the
way to Ephrath (that is, Bethlehem). 36Now this is the genealogy of Esau,
20 who is Edom.
And Jacob set a pillar on her grave,
which is the pillar of Rachel's grave to 2
this day. Esau took his wives from the daughters
of Canaan: Adah the daughter of Elon
21 the Hittite; Aholibamah the daughter of
Then Israel journeyed and pitched his Anah, the daughter of Zibeon the Hivite;
tent beyond the tower of Eder.
3
22 and Basemath, Ishmael's daughter,
And it happened, when Israel dwelt in sister of Nebajoth.
that land, that Reuben went and lay with
Bilhah his father's concubine; and Israel 4
heard about it. Now the sons of Jacob Now Adah bore Eliphaz to Esau, and
were twelve: Basemath bore Reuel.
5
23
the sons of Leah were Reuben, And Aholibamah bore Jeush, Jaalam,
Jacob's firstborn, and Simeon, Levi, and Korah. These were the sons of
Judah, Issachar, and Zebulun; Esau who were born to him in the land
of Canaan.
24
the sons of Rachel were Joseph and 6
Benjamin; Then Esau took his wives, his sons, his
daughters, and all the persons of his
25 household, his cattle and all his animals,
the sons of Bilhah, Rachel's and all his goods which he had gained
maidservant, were Dan and Naphtali; in the land of Canaan, and went to a
26
country away from the presence of his
and the sons of Zilpah, Leah's brother Jacob.
maidservant, were Gad and Asher.
И то же самое в dput
форме:
16 Then they journeyed from Bethel; and when there was still some distance to go to Ephrath, Rachel began to give birth and she [r]suffered severe labor.
17 When she was in severe labor the midwife said to her, “Do not fear, for now you have another son.”
18 It came about as her soul was departing (for she died), that she named him [s]Ben-oni; but his father called him [t]Benjamin.
19 So Rachel died and was buried on the way to Ephrath (that is, Bethlehem).
20 Jacob set up a pillar over her grave; that is the pillar of Rachel’s grave to this day.
21 Then Israel journeyed on and pitched his tent beyond the [u]tower of [v]Eder.
22 It came about while Israel was dwelling in that land, that Reuben went and lay with Bilhah his father’s concubine, and Israel heard of it.
The Sons of Israel
Now there were twelve sons of Jacob—
23 the sons of Leah: Reuben, Jacob’s firstborn, then Simeon and Levi and Judah and Issachar and Zebulun;
24 the sons of Rachel: Joseph and Benjamin;
25 and the sons of Bilhah, Rachel’s maid: Dan and Naphtali;
26 and the sons of Zilpah, Leah’s maid: Gad and Asher. These are the sons of Jacob who were born to him in Paddan-aram.
27 Jacob came to his father Isaac at Mamre of Kiriath-arba (that is, Hebron), where Abraham and Isaac had sojourned.
28 Now the days of Isaac were one hundred and eighty years.
29 Isaac breathed his last and died and was gathered to his people, an old man [w]of ripe age; and his sons Esau and Jacob buried him.
Esau Moves
36 Now these are the records of the generations of Esau (that is, Edom).
2 Esau took his wives from the daughters of Canaan: Adah the daughter of Elon the Hittite, and Oholibamah the daughter of Anah and the granddaughter of Zibeon the Hivite;
3 also Basemath, Ishmael’s daughter, the sister of Nebaioth.
4 Adah bore Eliphaz to Esau, and Basemath bore Reuel,
5 and Oholibamah bore Jeush and Jalam and Korah. These are the sons of Esau who were born to him in the land of Canaan.
6 Then Esau took his wives and his sons and his daughters and all [x]his household, and his livestock and all his cattle and all his goods which he had acquired in the land of Canaan, and went to another land away from his brother Jacob.
вывод dput :
"16\r\n Then they journeyed from Bethel. And These were the sons of Jacob who were\r\nwhen there was but a little distance to born to him in Padan Aram.\r\ngo to Ephrath, Rachel labored in\r\nchildbirth, and she had hard labor. 27\r\n Then Jacob came to his father Isaac at\r\n Mamre, or Kirjath Arba (that is, Hebron),\r\n17\r\n Now it came to pass, when she was in where Abraham and Isaac had dwelt.\r\nhard labor, that the midwife said to her,\r\n\"Do not fear; you will have this son 28\r\n Now the days of Isaac were one\r\nalso.\" hundred and eighty years.\r\n18\r\n And so it was, as her soul was 29\r\n So Isaac breathed his last and died,\r\ndeparting (for she died), that she called and was gathered to his people, being\r\nhis name Ben-Oni; but his father called old and full of days. And his sons Esau\r\nhim Benjamin. and Jacob buried him.\r\n19\r\n So Rachel died and was buried on the\r\nway to Ephrath (that is, Bethlehem). 36Now this is the genealogy of Esau,\r\n20 who is Edom.\r\n And Jacob set a pillar on her grave,\r\nwhich is the pillar of Rachel's grave to 2\r\nthis day. Esau took his wives from the daughters\r\n of Canaan: Adah the daughter of Elon\r\n21 the Hittite; Aholibamah the daughter of\r\n Then Israel journeyed and pitched his Anah, the daughter of Zibeon the Hivite;\r\ntent beyond the tower of Eder.\r\n 3\r\n22 and Basemath, Ishmael's daughter,\r\n And it happened, when Israel dwelt in sister of Nebajoth.\r\nthat land, that Reuben went and lay with\r\nBilhah his father's concubine; and Israel 4\r\nheard about it. Now the sons of Jacob Now Adah bore Eliphaz to Esau, and\r\nwere twelve: Basemath bore Reuel.\r\n 5\r\n23\r\n the sons of Leah were Reuben, And Aholibamah bore Jeush, Jaalam,\r\nJacob's firstborn, and Simeon, Levi, and Korah. These were the sons of\r\nJudah, Issachar, and Zebulun; Esau who were born to him in the land\r\n of Canaan.\r\n24\r\n the sons of Rachel were Joseph and 6\r\nBenjamin; Then Esau took his wives, his sons, his\r\n daughters, and all the persons of his\r\n25 household, his cattle and all his animals,\r\n the sons of Bilhah, Rachel's and all his goods which he had gained\r\nmaidservant, were Dan and Naphtali; in the land of Canaan, and went to a\r\n26\r\n country away from the presence of his\r\n and the sons of Zilpah, Leah's brother Jacob.\r\nmaidservant, were Gad and Asher.\r\n"
Бонус:
Я пытался скачать PDF, используя:
download.file("http://www.apuritansmind.com/wp-content/uploads/PDF/NewKingJamesBible.pdf",
"new_king_james_bible.pdf")
Файлразмер 6,5 МБ, но при его открытии он абсолютно пустой.Зачем?Мне пришлось загрузить его вручную и прочитать с компьютера, чтобы извлечь текст с помощью pdftools
.