A
A
abyr782015-03-04 11:42:19
Perl
abyr78, 2015-03-04 11:42:19

How from another?

I found it like this: while reading Real World Haskell, I learned about the combinatorial parsing library Parsec. The examples in the book are amazing. Unlike the traditional approach, there is no division into lexical analysis (selection of "words" - lexemes) and syntactic analysis (transformation of a stream of "words" into an ordered data structure) - in combinatorial parsing, these two stages are combined. Small functions are taken that recognize elements of the text, and then they are combined according to the syntax of the text. Thus, the combination of functions itself directly reflects grammar, and it, of course, is also a program for parsing text. Like any good idea, Parsec has many imitations. For Python combinatorial parsers, there were as many as two already three already four - Pysec, Pyparsing, LEPL (for Python 2.6 / 3.0) and funcparselib.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Andrey Andrianov, 2015-03-04
@aTwice

1) save the 1st file in CSV format so as not to suffer. I will call it the 1st file
2) Collect the 1st fileset from the full name. 3) open the 3rd file
for writing 4) Read the 2nd file line by line, parse the line, extract the full name, phone number. If the full name is in set, then save the line full name + phone number in the 3rd file .

A
Alexey Cheremisin, 2015-03-04
@leahch

Tavk seems to be a fairly simple task. If all full names from the first file fit into memory, for example, in a dict, then:
1) create a dict with a key by full name from the first file and an empty array
2) run through the second file line by line and check the full name by key, if there is a key, then add to phone array.
3) We save all records from dict where the array is not empty.

# stage 1
all_fio = dict()
with open('myfiofile','r') as fp_fio:
  for line in fp_fio:
     (_f,_i,_o,_,_)  = line.split(';')
     _fio = _f+' '+_i +' ' + _o
     all_fio[_fio] = []

# stage 2
with open('mybilphonelog','r') as fp_log:
  for line in fp_log:
     (_t1,_t2,_fio,_)  = line.split(';')
     if all_fio.has_key(_fio):
        all_fio[_fio].append(_t1)
        all_fio[_fio].append(_t2)

# stage 3
import json
json.dump(all_fio, open('myresultfile','w'))

PS. didn't debug the code! there may be bugs

V
Vladimir Martyanov, 2015-03-04
@vilgeforce

Is it not an option to drive all this into mysql and get the necessary data with a couple of queries?

S
ShamblerR, 2015-03-04
@ShamblerR

fuck you guys che hu .. turn that back
1. does everyone have this phone
2. Is there always tabs, even a feast of missing lines
If all you need
is to take 1 word and after 5 tabs take another, then there is 1 line.
Give us an example file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question