# install.packages("tesseract")
library(tesseract)
eng = tesseract("eng")
text <- tesseract::ocr("/Users/nishantaneja/Desktop/Screenshot 2022-10-24 at 10.45.51.png", engine = eng)
cat(text)
## The India-Pakistan cricket rivalry is one of the most intense sports rivalries in the world.!"II?] The tense relations
## between the two nations, resulting from bitter diplomatic relationships and conflict that originated during the Partition of
## British India into India and Pakistan in 1947, the Indo-Pakistani Wars, and the Kashmir conflict, laid the foundations for the
## emergence of an intense sporting rivalry between the two nations who had shared a common cricketing heritage.
##
## The two sides first played in 1952, when Pakistan toured India. Test and, later, limited overs series have been played ever
## since, although a number of planned tours by both sides have been cancelled or aborted due to political factors. No cricket
## was played between the two countries between 1962 and 1977 due to two major wars in 1965 and 1971 and the 1999
## Kargil War and the 2008 Mumbai terrorist attacks have also interrupted cricketing ties between the two nations. /51l4]
To check what languages you have in the package, you can use tesseract_info() as follows:
tesseract_info()
## $datapath
## [1] "/Users/nishantaneja/Library/Application Support/tesseract5/tessdata/"
##
## $available
## [1] "eng" "osd"
##
## $version
## [1] "5.0.1"
##
## $configs
## [1] "alto" "ambigs.train" "api_config" "bigram"
## [5] "box.train" "box.train.stderr" "digits" "get.images"
## [9] "hocr" "inter" "kannada" "linebox"
## [13] "logfile" "lstm.train" "lstmbox" "lstmdebug"
## [17] "makebox" "pdf" "quiet" "rebox"
## [21] "strokewidth" "tsv" "txt" "unlv"
## [25] "wordstrbox"
English is a default addition in this package but if you would like to add more languages you can use tesseract_download() command to do the same and then extract text from the pic that you have at your disposal.
What if we have a pdf and we want to convert that into raw text ? Can we do that ? Yes.. definitely, we just have to convert the pdf into jpg first and ensure its of good quality so that tesseract package can give us a decent output.
Usind pdf_convert from pdftools to get the pdf in png format…
pngfile <- pdftools::pdf_convert('/Users/nishantaneja/Desktop/Learning Files/Books/When money dies_ The nightmare of the Weimar collapse ( PDFDrive ).pdf', pages = 6:11, dpi = 600)
## Converting page 6 to When money dies_ The nightmare of the Weimar collapse ( PDFDrive )_6.png... done!
## Converting page 7 to When money dies_ The nightmare of the Weimar collapse ( PDFDrive )_7.png... done!
## Converting page 8 to When money dies_ The nightmare of the Weimar collapse ( PDFDrive )_8.png... done!
## Converting page 9 to When money dies_ The nightmare of the Weimar collapse ( PDFDrive )_9.png... done!
## Converting page 10 to When money dies_ The nightmare of the Weimar collapse ( PDFDrive )_10.png... done!
## Converting page 11 to When money dies_ The nightmare of the Weimar collapse ( PDFDrive )_11.png... done!
now converting to text using the tesseract package…
text2 = ocr(pngfile)
cat(text2)
## Prologue
##
## WHEN a nation's money is no longer a source of security, and when inflation
## has become the concern of an entire people, it is natural to turn for information
## and guidance to the history of other societies who have already undergone this
## most tragic and upsetting of human experiences.
##
## Yet to survey the great array of literature of all kinds — economic, military,
## social, historic, political, and biographical — which deals with the fortunes of
## the defeated Central Powers after the First World War is to discover one
## particular shortage. Either the economic analyses of the times (for reasons best
## known to economists who sometimes tend to think that inflations are deliberate
## acts of fiscal policy) have ignored the human element, to say nothing in the case
## of the Weimar Republic and of post-revolutionary Austria of the military and
## political elements; or the historical accounts, though of impressive erudition and
## insight, have overlooked — or at least much underestimated — inflation as one
## of the most powerful engines of the upheavals which they narrate.
##
## The first-hand accounts and diaries, on the other hand, although of incalculable
## value in assessing inflation from the human aspect, have tended even in
## anthological form either to have had too narrow a field of vision — the battle
## seen from one shell-hole may look very different when seen from another — or
## to recall the financial extravaganza of 1923 in such a general way as to
## underplay the many years of misfortune of which it was both the climax and the
## herald.
##
## The agony of inflation, however prolonged, is perhaps somewhat similar to acute
## pain — totally absorbing, demanding complete attention while it lasts; forgotten
## or ignorable when it has gone, whatever mental or physical scars it may leave
## behind. Some such explanation may apply to the strange way in which the
## remarkable episode of the Weimar inflation has been divorced — and vice versa
## — from so much contemporary incident. And yet, one would have thought,
## considering how persistent, extended and terrible that inflation was, and how
## baleful its consequences, no study of the period could be complete without
## continual reference to the one obsessive circumstance of the time.
##
## The converse is also true: except at the narrowest level of economic treatise or
## personal reminiscence, how can a fair account of the German inflation be given
## outside the context of political subversion by Nationalists and by Communists,
## or the turmoil in the Army, or the quarrel with France, or the problem of war
## reparations, or the parallel hyperinflations in Austria and Hungary? How can one
## gauge the political significance of inflation, or judge the circumstances in which
## inflation in an industrialised democracy takes root and becomes uncontrollable,
## unless its course is charted side by side with the political events of the moment?
## The Germany of 1923 was the Germany of Ludendorff as well as of Stinnes, of
## Havenstein as well as of Hitler. For all their different worlds, of the Army, of
## industry, of finance and of politics, these four grotesque figures stalking the
## German stage may equally be represented as the villains of the play: Ludendorff,
## the soulless, humourless, ex-Quartermaster-General, worshipper of Thor and
## Odin, rallying point and dupe of the forces of reaction; Stinnes, the plutocratic
## profiteer who owed allegiance only to Mammon; Havenstein, the mad banker
## whose one object was to swamp the country with banknotes; Hitler, the power-
## hungry demagogue whose every speech and action even then called forth all that
## was evil in human nature. In i
##
## respect of Havenstein alone the description is of course unjust; but the fact that
## this highly-respected financial authority was sound in mind made no difference
## to the wreckage he wrought.
##
## Or one may say that there were no real human villains; that given the economic
## and political cues, actors would have been in the wings to come on and play the
## parts which circumstances dictated. Certainly there were many others as
## reprehensible and irresponsible as those who played the leading roles. ‘The
## German people were the victims. The battle, as one who survived it explained,
## left them dazed and inflation-shocked. They did not understand how it had
## happened to them, and who the foe was who had defeated them.
## This book presents a few new facts, but many forgotten facts and many hitherto
## unpublished opinions — most usefully of those who could observe events
## objectively because their purses, health and security were unaffected by what
## they were witnessing. The most bountiful store of such material are the records
## of the British Foreign Office, supplied originally by the embassy in Berlin where
## Lord D'Abernon prosecuted in those years one of the most successful
## ambassadorships of the age. His information was amply augmented by the
## consular service in every important city in Germany, as by reports from
## individual members of the Allied commissions concerned with reparations or
## disarmament. The documents in the Public Record Office, apart from being
## among the more accessible, are also probably the most important source
## available, not only because the British Embassy through D'Abermmon was in
## exceptionally close touch at all times with Germany's senior politicians, but
## because the withdrawal of the United States presence at the start of 1933, and the
## almost complete interruption of any co mmunication between Berlin and Paris
## earlier still, rendered sporadic or superficial what might have been information
## of comparable value. Supplemented by contemporary German material, I have
## not hesitated to draw as fully as seemed justified on those papers.
##
## I have tried as far as possible to keep these actions, reactions and interactions in
## their proper historical sequence in the hope that this perhaps obvious order is in
## this case both a new and enlightening one, and the better to expose a number of
## important but little-noticed relationships.
##
## In relating the story, I have followed, and at times had to hang on grimly to a
## special thread which wound through Austria, Hungary, Russia, Poland and
## France, too. It is one which the great authorities have sometimes seemed to lose
## touch with: the effect of inflation on people as individuals and as nations, and
## how they responded to it.
##
## I have not, however, dared to draw hard and fast conclusions about humanity and
## inflation on the basis of what I have written
##
## here: the facts speak very well for themselves. Still less have I expounded any
## economic lessons or indulged in theoretical explanations of economic
## phenomena. This is emphatically not an economic study. Yet inflation is about
## money as well as people, and it would be impossible to tell the tale without
## introducing figures, sometimes vast figures, again and again. Vast figures were
## what the people of central Europe were assailed by and bludgeoned with for
## years on end until they could bear no more. The value of the mark in 1922 and
## 1923 was in everyone's mind; but who could comprehend a figure followed by a
## dozen ciphers?
##
## In October 1923 it was noted in the British Embassy in Berlin that the number of
## marks to the pound equalled the number of yards to the sun. Dr Schacht,
## Germany's National Currency ii
##
## Commissioner, explained that at the end of the Great War one could in theory
## have bought 500,000,000,000 eggs for the same price as that for which, five
## years later, only a single egg was procurable. When stability returned, the sum of
## paper marks needed to buy a gold mark was precisely equal to the quantity of
## square millimetres in a square kilometre. It is far from certain that such
## calculations helped anyone to understand what was going on; so let the un-
## mathematical reader take heart.
##
## Because of the varying ways in which nations express large amounts, I have
## tried to avoid notations such as billions and trillions upon which custom is
## confusingly divided. When I have departed from this practice, due indication has
## been given.
##
## It has been harder in the writing to find enough simple epithets to describe
## without repetition the continuous, worsening succession of misfortunes that
## struck the German people at this time. It was a difficulty noticed and noted by
## Mr Lloyd George writing in 1932, who said that words such as ‘disaster’, 'ruin’,
## and 'catastrophe' had ceased to rouse any sense of genuine apprehension any
## more, into such common usage had they fallen. Disaster itself was devalued: in
## contemporary documents the word was used year after year to describe
## situations incalculably more serious than the time before. When the mark finally
## dropped out of sight and ruin was all around, there were still Germans to be
## heard predicting Katastrophe for the future.
##
## I have tried, therefore, to limit the number of disasters, crashes, cataclysms,
## collapses and catastrophes in the text, as well as the degree of crisis and chaos,
## to a digestible amount, to which the reader may mentally add as much more as
## his power of sympathy dictates.
##
## In one other matter the reader must act independently. It has been necessary
## frequently to give the 1920s' sterling or dollar equivalents of the mark sums
## involved, in order to show the degree of the mark's depreciation. The continuing
## process of inflation of all western countries makes conversion to present-day
## value an unrewarding occupation. For the lowest range of conversions have kept
## to the £sd system of 12 pence to the shilling am shillings to the pound. At this
## distance, cost of living comparisons are fairly futile; yet it may be useful to
## reckon that in the middle of 1975 it was necessary to multiply every 1920
## sterling figure by almost 15 times to find an equivalent. Thus a wage of £200 in
## 1919 may be worth £3,000 today; a sum of ten shillings worth seven or eight
## pounds. For dollars, a multiplicator of six or eight could be enough. If a mark in
## 1913 would buy almost a pound's worth of goods services in 1975 (some items,
## clearly, were much more expensive than others such as labour much cheaper in
## real terms than now) No simple but rough conversion is available for sterling
## readers whom it amuses or vexes to imagine paying £148,000,000 for a postage
## stamp: for marks they should read pounds.
##
## There is no constant rule of thumb for coping accurately witt later stages of the
## inflation. Until autumn 1921 the internal depreciation of the mark sometimes
## lagged far behind its fall abroad; making Germany such a haven for tourists.
## Later on (from beginning of 1922), as public confidence in the mark dissolved,
## domestic prices adjusted themselves rapidly upwards in tune to the dollar rate,
## and at the end were even heftily anticipating mark's fall. This was one more of
## the phenomena of the times which fatally confused the issue then and which
## exercised the interest of economists for many years afterwards.
##
## ill
##
## This is, I believe, a moral tale. It goes far to prove the revolutionary axiom that if
## you wish to destroy a nation you must corrupt its currency. Thus must sound
## money be the first bastion of a society's defence.
## IV
Thanks for watching, See you in the next video :)