I´m trying to learn C#, coming from a Python/PHP background, and I´m trying to port a script from Python to getting started.
The script reads a text file line by line (about 150K lines), apply a list of regex until one is matched, get the named groups results and add the values as properties of a class.
Here´s how the data looks like (each line starting by 'No.' is the beginning of a new record):
No.813177294 09/01/1987 150 Tit.INCAL INDÚSTRIA DE CALÇADOS LTDA (BR/PE) *PARÁGRAFO ÚNICO DO ART. 162 DA LPI. Procurador: ROBERTO C. FREIRE No.901699870 02/06/2009 LD6 *Exigência Formal não respondida, Pedido de Registro de Marca considerado inexistente, de acordo com o Art. 157 da LPI No.830009817 12/12/2008 003 Tit.BIOLAB SANUS FARMACÊUTICA LTDA. (BR/SP) C.N.P.J./C.I.C./NºINPI : 49475833000106 Apres.: Nominativa ; Nat.: De Produto Marca: ENXUG NCL(9) 05 medicamentos para uso humano; preparações farmacêuticas; diuréticos, analgésicos; anestésicos; anti-helmínticos; antibióticos; hormônios para uso medicinal. Procurador: CRUZEIRO/NEWMARC PATENTES E MARCAS LTDA
And how the regex looks like:
regexp = {
# No.123456789 13/12/2008 560
# No.123456789 13/12/2008 560
# No.123456789 13/12/2008 560
# No.123456789 560
'number': re.compile(r'No.(?P<Number>[\d]{9}) +((?P<Date>[\d]{2}/[\d]{2}/[\d]{4}) +)?(?P<Code>.*)'),
# NCL(7) 25 no no no no no ; no no no no no no; *nonono no non o nono
# NCL(9) 25 no no no no no ; no no no no no no; *nonono no non o nono
'ncl': re.compile(r'NCL\([\d]{1}\) (?P<Ncl>[\d]{2})( (?P<Especification>.*))?'),
'doc': re.compile(r'C.N.P.J./C.I.C./NºINPI : (?P<Document>.*)'),
'description': re.compile(r'\*(?P<Description>.*)'),
...
}
Now my questions:
1) Can I use the same concept, applying each of a Dictionary<string, Regex> in each line until one is matched?
2) If I do, there´s a way to get a Dictionary<string, string> of the named groups results? (At this stage I can treat everything as a string).
3) If supposed I have a class like this...
class Record
{
public string Number { get; set; }
public string Date { get; set; }
public string Code { get; set; }
public string Ncl { get; set; }
public string Especification { get; set; }
public string Document { get; set; }
public string Description { get; set; }
}
...there is a way to set the properties with the values of the named groups?
4) I´m totally missing the point here, trying to code in a static typed language still thinking in a dynamically typed one? If this is the case, what can I do?
Sorry for this somewhat lengthy question. I really tried to resume to make this shorter :-)
Thanks in advance.