Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Speed this Code Up?
Message
From
05/07/2006 14:20:18
 
 
To
05/07/2006 12:03:16
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01133775
Message ID:
01133945
Views:
12
Actually, I liked your ideas so much that I massaged it somewhat and may use it instead. :o) Thank Cetin!


>Tracy,
>You solved it already:) Anyway here is a divide&conquer approach that might help:
>
>Clear
>TEXT to lcSamples noshow
>B10 TS 4004, 100 N Main St, TX, 05, WM, 132lbs, 62", More Comments
>C32 TS ABC123, TX, 2005, 100 N MAIN ST, 2 CHILDREN IN VEH
>A10 TS 100 N MAIN ST, ABC123, SC, 06, WM 150LBS 60"
>C10 TS SC, 4003, 04, 100 N MAIN ST
>ENDTEXT
>
>loParser = Createobject('myParser')
>loParser.Parse(m.lcSamples)
>For px=1 To Alen(loParser.aProcessed)
>  ? 'Record#',m.px,;
>    loParser.aProcessed[m.px].Id,;
>    loParser.aProcessed[m.px].vlTagYEar,;
>    loParser.aProcessed[m.px].vlTagState,;
>    loParser.aProcessed[m.px].location,;
>    loParser.aProcessed[m.px].vlTag, ;
>    loParser.aProcessed[m.px].Comments
>Endfor
>
>Define Class myParser As Custom
>  cStates = 'AR,WY,TX,SC,NY'
>  Procedure Init
>  Endproc
>
>  Procedure Parse(tcText)
>    Local ix
>    Local Array aProcess[1]
>    lnLines = Alines(aProcess,m.tcText)
>    This.AddProperty('aProcessed['+Transform(m.lnLines)+']')
>
>    Create Cursor _dummy_ (Id i,vltag i,vltagstate i,vltagyear i,location i,comments i)
>    For ix=1 To Alines(aProcess,m.tcText)
>      Scatter Name This.aProcessed[m.ix] Blank
>      This.aProcessed[m.ix].Id = Alltrim(Strextract(aProcess[m.ix],'',' TS '))
>      This.ProcessLine(aProcess[m.ix],m.ix)
>    Endfor
>    Use In _dummy_
>  Endproc
>
>  Procedure ProcessLine(tcLine,tnObjectID)
>    *    ? m.tcLine, m.tnObjectID
>    Local lcParse,lnWords,ix
>    lcParse = Strextract(m.tcLine,' TS ')
>    lnWords = Getwordcount( m.lcParse,',' )
>    Local Array aPhrases[Max(m.lnWords,5)]
>    aPhrases = ''
>    For ix=1 To m.lnWords
>      aPhrases[m.ix] = Alltrim(Getwordnum( m.lcParse,m.ix,',' ))
>    Endfor
>    This.parseItems(@aPhrases,m.tnObjectID)
>  Endproc
>
>  Procedure ParseItems(taPhrases,m.tnObjectID)
>    With This.aProcessed[m.tnObjectID]
>      .vlTagYear = This.FindYear(@taPhrases)
>      .vlTagState = This.FindState(@taPhrases)
>      .location = This.FindLocation(@taPhrases)
>      .vlTag = This.FindTag(@taPhrases)
>      .comments = This.getRest(@taPhrases)
>    Endwith
>  Endproc
>
>  Procedure FindYear(taPhrases)
>    Local ix,lnYear
>    For ix=1 To Alen(taPhrases)
>      If This.IsYear(taPhrases[m.ix]) && actually VFP is smart and this might be much shorter
>        lnYear = Year(Ctod('1/1/'+taPhrases[m.ix]))
>        Adel(taPhrases,m.ix)
>        Dimension taPhrases[Alen(taPhrases)-1]
>        Return m.lnYear
>      Endif
>    Endfor
>    Return 0
>  Endproc
>
>  Procedure FindState(taPhrases)
>    Local ix,lcState
>    For ix=1 To Alen(taPhrases)
>      If taPhrases[m.ix] $ This.cStates And Len(taPhrases[m.ix]) = 2
>        lcState = taPhrases[m.ix]
>        Adel(taPhrases,m.ix)
>        Dimension taPhrases[Alen(taPhrases)-1]
>        Return m.lcState
>      Endif
>    Endfor
>    Return ''
>  Endproc
>
>  Procedure FindLocation(taPhrases)
>    Local ix,lcLocation
>    For ix=1 To Alen(taPhrases)
>      If ( Isdigit(taPhrases[m.ix]) And Occurs(' ', taPhrases[m.ix]) > 0 ) Or ;
>          ( '/\' $ taPhrases[m.ix] )
>        lcLocation = taPhrases[m.ix]
>        Adel(taPhrases,m.ix)
>        Dimension taPhrases[Alen(taPhrases)-1]
>        Return m.lcLocation
>      Endif
>    Endfor
>    Return ''
>  Endproc
>
>  Procedure FindTag(taPhrases)
>    Local ix,lcTag
>    For ix=1 To Alen(taPhrases)
>      If ( Occurs(' ', taPhrases[m.ix]) = 0 )
>        lcTag = taPhrases[m.ix]
>        Adel(taPhrases,m.ix)
>        Dimension taPhrases[Alen(taPhrases)-1]
>        Return m.lcTag
>      Endif
>    Endfor
>    Return ''
>  Endproc
>
>  Procedure getRest(taPhrases)
>    Local ix,lcComments
>    lcComments = ''
>    For ix=1 To Alen(taPhrases)
>      If ( !Empty(taPhrases[m.ix]) )
>        lcComments = taPhrases[m.ix] + Space(1)
>      Endif
>    Endfor
>    Return Trim(m.lcComments)
>  Endproc
>
>
>  Procedure IsAllDigit(tcValue)
>    Return Empty(Chrtran(m.tcValue,'0123456789',''))
>  Endproc
>
>  Procedure IsYear(tcValue)
>    Return This.IsAllDigit(m.tcValue) And ;
>      InList(Len(m.tcValue),2,4) And ;
>      BETWEEN(Year(Ctod('1/1/'+m.tcValue)),Year(Date())-3,Year(Date())+1)
>  Endproc
>Enddefine
>
Cetin
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Reply
Map
View

Click here to load this message in the networking platform