MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Difficulty with patterns

  • To: mathgroup at smc.vnet.net
  • Subject: [mg122296] Re: Difficulty with patterns
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Mon, 24 Oct 2011 05:12:59 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201110231024.GAA10547@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

Try this:

Clear[space]
space[s_String] :=
  StringJoin@
   Rest@Replace[Characters@s, u_?UpperCaseQ :> Sequence[" ", u], {1}]
Grid[m = Most@
     Rest@Flatten[
       WolframAlpha[
        "USA", {{"LargestCities:CountryData", 1}, "ComputableData"},
        PodStates -> {"LargestCities:CountryData__More",
          "LargestCities:CountryData__More"}],
       1] /. {city_String, _, _} :> space@city, Frame -> All]

Bobby

On Sun, 23 Oct 2011 05:24:34 -0500, McHale, Paul  
<Paul.McHale at excelitas.com> wrote:

> I have recently become increasingly uncomfortable with my areas of  
> ignorance with Mathematica.  The Virtual conference has some really cool  
> demos.  In one, a website is read in and a table of data extracted.   
> Without patterns, it would have been very difficult.  Need a little help  
> with an example.
>
> Example 1 uses my old standby, the Table[] function.  Works fine.  I am  
> attempting to get better with patterns, so I tried example 2 and 3.   
> They work, but gives several errors about use of stringjoin needing  
> strings.  What am I doing wrong?
>
> Error: StringJoin::string: String expected at position 1 in  
> StringJoin[n].
>
> (* Load string from WolframAlpha  *)
> m WolframAlpha["usa",{{"LargestCities:CountryData",1},"ComputableData"},
> PodStates->{"LargestCities:CountryData__More","LargestCities:CountryData__More"}];
>
> (* example 1 *)
> mNew=Flatten[m,1];
> mNew=Drop[mNew,1];
> mNew=Drop[mNew,-1];
> mNew=Table[{i[[1,1]] <> i[[1,2]] <> i[[1,2]] ,i[[2]]},{i,mNew}];
> Grid[mNew,Frame->All]
>
> (* example 2 *)
> Clear[n,o,p,q];
> mNew=Cases[m, {{n_String,o_String,p_String},q_} -> { n <>  ", " <> o  <>  
> ", " <>  p,q},Infinity ];
> Grid[mNew,Frame->All]
>
> (* example 3 *)
> Clear[n,o,p,q];
> mNew=Cases[m, {{n_,o_,p_},q_} -> { n ,  ", ", o  , ", ", p,q},Infinity ];
> mNew = mNew /. {n___,q_Integer} -> {StringJoin[n],q};
> Grid[mNew,Frame->All]
>
> I even tried,
> mNew = Flatten[m, 1];
> mNew = Drop[mNew, 1];
> mNew = Drop[mNew, -1];
> mNew = Table[{Head[i[[1, 1]]], Head[i[[1, 2]]], Head[ i[[1, 2]]] ,
>     i[[2]]}, {i, mNew}];
> (*mNew=Table[{i[[1,1]] <> i[[1,2]] <> i[[1,2]] ,i[[2]]},{i,mNew}];*)
> Grid[mNew, Frame -> All]
>
> They are all strings!
>
>
> Thanks,
> Paul
>
>
> Paul McHale  |  Electrical Engineer, Energetics Systems  |  Excelitas  
> Technologies Corp.
> =09
> Phone:   +1 937.865.3004   |   Fax:  +1 937.865.5170   |   Mobile:   +1  
> 937.371.2828
> 1100 Vanguard Blvd, Miamisburg, Ohio 45342-0312 USA
> Paul.McHale at Excelitas.com
> www.excelitas.com
>
>
>
> Please consider the environment before printing this e-mail.
> This email message and any attachments are confidential and proprietary  
> to Excelitas Technologies Corp. If you are not the intended recipient of  
> this message, please inform the sender by replying to this email or  
> sending a message to the sender and destroy the message and any  
> attachments.
> Thank you
>
>


-- 
DrMajorBob at yahoo.com



  • Prev by Date: Re: runs slowly?
  • Next by Date: Re: Difficulty with patterns
  • Previous by thread: Difficulty with patterns
  • Next by thread: Re: Difficulty with patterns