I
I
Ilya2019-04-29 21:33:27
PHP
Ilya, 2019-04-29 21:33:27

How to parse a catalog of books?

The library has a large book catalog. Here are three lines from it:

Arthur Conan Doyle – The Adventures of Sherlock Holmes, George Newnes 1892
Ernest Hemingway – The Old Man and the Sea, Charles Scribner's Sons 1952
Ralph Leighton, Richard Feynman – Surely You're Joking, Mr. Feynman!, W.W. Norton 1985

Please tell me how to isolate three entities from each line: the author of the book, the title and the publisher with the year. I need this to move a directory to a database.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
hzzzzl, 2019-04-29
@sidorchik

Is this always the same format? then you can stupidly in the forehead in a cycle

s = 'Arthur Conan Doyle – The Adventures of Sherlock Holmes, George Newnes 1892'
author = s.split('–')[0].trim()
by = s.split('–')[1].trim()
last = by.lastIndexOf(' ')
book = by.slice(0, l).trim()
year = by.slice(l).trim()

UPD
ah, this is a question about php, I'm not strong in it :) well, somehow it's possible for anyone too

K
Kutuzov_ska, 2019-04-29
@Kutuzov_ska

I am sure that the regular season will definitely help here. There will be something like preg_match('/(.*)-(.*),(.*)/', .... $kek)
$kek[0] - Author, etc.
And try the coolest method for pride :) If there is and will be an opportunity.
Use the FANN library
https://www.php.net/manual/ru/book.fann.php
And here is the tutorial https://phpnick.ru/posts/category/php/48
Make a small dataset by analogy
And now you have an artificial intelligence that parses books :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question