Em Andamento

Text string parsing in Python

This project involves writing? 1 function in Python? that? takes? a string of text (having to do? w/? prices --? e.g. "$5 per person" or "$5 - 10 for students" and? parses our the price values).

The ? function would takes a potential price string as input and returns a tuple ((min,max),details,parsed).

Here:

? ? ? -"(min,max)" is a tuple of two floats that are either the min and

max price if the price was parsed correctly or None if? it was

parsed incorrectly.

? ? ? -"details" is a string with details about the price, if any

details about the price were in the string (e.g. "Students" in the

string "$25 Students"). If a string containing details is parsed at

all, these details should make it to this string. If a price string

has no price details or we were unable to parse the price, "details"

can be None or empty.

? ? ? -"parsed" is a boolean variable that is True if the input string

was successfully parsed and False if the input was unable to be

parsed.

There's already python code (see bottom of

this doc) which parses a few simple cases of price strings.

Currently, it recognized:

1."Free", with or without a $ sign before it. (with arbitrary spaces

in between and afterwards) --> gets parsed as min_price,max_price =

0,0.

? ? ? ? --examples: "free", "Free", "$Free"

2. simple price range, minprice - maxprice, (with or without dollar

signs at the beginning, with arbitrary spaces in between and

afterwards).

? ? ? ? --examples: "25-30", "$15? - $27.53", "? $12? ? -20"

3. simple price --> gets parsed as min_price, max_price = simple

price, simple price.

? ? ? ? --examples: "20.13", "? ? $25.27", etc.

Your goal is to add to the code below by doing this:

1. determine all patterns from a provided list of examples &

keep track of them in a list

2. for each pattern, write a regular expression/regular

expressions/function that parses only strings matching this pattern

3. add a case to the below function that attempts to match this

pattern and returns the appropriate ((min,max),details,True) if

successful.

## Deliverables

==========================================

HERE IS THE CURRENT PRICE PARSING CODE (in Python)

==========================================

--------------------------------------------------

import re

free_price = [url removed, login to view]('^\s*\$?\s*[fF][rR][eE][eE]\s*$')

simple_price = [url removed, login to view]('^\s*\$?(?P<price>[0-9]+\.?[0-9]*)\s*$')

simple_range = [url removed, login to view]('^\s*\$?(?P<price1>[0-9]+\.?[0-9]*)\s*\-+\s*\$?(?P<price2>[0-9]+\.?[0-9]*)\s*$')

def price_parse(pricestr):

? ? ? m = [url removed, login to view](pricestr)

? ? ? if m:

? ? ? ? ? ? ? return (float([url removed, login to view]('price')),float([url removed, login to view]('price'))),True

? ? ? m = [url removed, login to view](pricestr)

? ? ? if m:

? ? ? ? ? ? ? return (float([url removed, login to view]('price1')),float([url removed, login to view]('price2'))),True

? ? ? m = [url removed, login to view](pricestr)

? ? ? if m:

? ? ? ? ? ? ? return (0.0,0.0),True

? ? ? return (None,None),False

---------------------------------------------------------------

Later on I'll also provide you with a good number of test price string samples (about 25,000 or so).

Habilidades: Engenharia, MySQL, PHP, Python, Arquitetura de software, Teste de Software, Hospedagem Web, Gestão de Site , Teste de Website

Ver mais: python string parsing, writing patterns, writing expressions, to string, the p.i.c. group, text to string, text pattern matching, test cases python, string the, string pattern matching in c, string pattern matching, string pattern match, string pattern, string matching in c, string match, string i, string 2, rr sign in, regular expression with examples, regular expressions list, regular expressions in c, regular expressions examples, regular expressions c, regular expression no, regular expression in c

Acerca do Empregador:
( 48 comentários ) United States

ID do Projeto: #3029339

Premiar a:

slimbvw

See private message.

$255 USD em 7 dias
(153 Avaliações)
7.5

17 freelancers estão ofertando em média $140 para este trabalho

renardpaul

See private message.

$212.5 USD in 7 dias
(100 Comentários)
6.5
dancoderdan

See private message.

$127.5 USD in 7 dias
(57 Comentários)
6.5
mkowalczuk

See private message.

$170 USD in 7 dias
(26 Comentários)
5.8
viktorkerkez

See private message.

$170 USD in 7 dias
(16 Comentários)
5.0
pitaji

See private message.

$170 USD in 7 dias
(11 Comentários)
4.6
zvision

See private message.

$106.25 USD in 7 dias
(50 Comentários)
4.3
adhd

See private message.

$170 USD in 7 dias
(18 Comentários)
4.1
adeelj

See private message.

$127.5 USD in 7 dias
(10 Comentários)
3.3
stwdev

See private message.

$93.5 USD in 7 dias
(2 Comentários)
3.1
homi12345

See private message.

$170 USD in 7 dias
(10 Comentários)
2.9
mihaigociu

See private message.

$85 USD in 7 dias
(3 Comentários)
2.6
ukimi367

See private message.

$85 USD in 7 dias
(8 Comentários)
1.7
borisdanilovich

See private message.

$187 USD in 7 dias
(0 Comentários)
0.0
asp093

See private message.

$85 USD in 7 dias
(1 Comentário)
0.0
duncangauld

See private message.

$170 USD in 7 dias
(0 Comentários)
0.0
iakvw

See private message.

$85 USD in 7 dias
(0 Comentários)
0.0
kama16

See private message.

$85 USD in 7 dias
(0 Comentários)
0.0