5
$\begingroup$
  1. I need to extract three data, like that: (1.05, 1.37,A) from an imported list of plain texts:

"... Syntax of parallax is : 'value quality [error] bibcode' value : parallax value quality : flag of quality (A=best quality -> E=worst quality, ~ =unknown quality) [error] : mean error bibcode : bibcode of the parallax reference Parallaxes mas : 1.05 [1.37] A 2007A&A...474..653V...,

........ Parallaxes mas : xxxxxx [xxxxx] xxx ................., etc...."

I did the following code:

datatoda = Import[".............", "Plaintext"];

In[28]:= StringCases[datatoda, "Parallaxes mas :" ~~ __ ~~ (x : NumberString) ~~ "[" ~~ (y : NumberString) ~~ "]" ~~ (z : WordCharacter ...) ~~ DatePattern["Year"]~~__ :> ToExpression@{x, y, z}]

Out[28]= {{}}

But I can not see where I am failing.

I need a list like that:{ {1.05,1.37,A},{....,...,.....}, etc....... }

  1. Sometimes there is no numbers in pattern of the plain text data ( Parallaxes mas : ~ [~] ~ ~ ) , in that case the sublist has to be {{..,...,..},......,{N/A},...etc}. How can I implement it?

EDIT1.: This is an e.g of link where the plaint text comes from: http://simbad.u-strasbg.fr/simbad/sim-id?Ident=%402515791&Name=HD%20164816&submit=submit Thanks!

$\endgroup$
1
  • 1
    $\begingroup$ I think you have not allowed for some spaces in your pattern. $\endgroup$
    – george2079
    Aug 29, 2015 at 13:55

1 Answer 1

2
$\begingroup$

I Got a positive result using :

StringCases[datatoda, {"Help" ~~ RegularExpression["\\s+"] ~~ a : __ ~~ RegularExpression["\\s+"] ~~ "other" ~~ RegularExpression["\\s"] ~~ ___ ~~ "Parallaxes mas :" ~~ RegularExpression["\\s+"] ~~ x : NumberString ~~ RegularExpression["\\s"] ~~ "[" ~~ y : NumberString ~~ "]" ~~ RegularExpression["\\s"] ~~ z : WordCharacter ~~ RegularExpression["\\s"] ~~ "2007A&A" :> StringTrim@{a, x, y, z}}];

(I introduced, also, a new data also in the sublist)

{{{"HD 164019", "1.05", "1.37", "A"}}, {{"* 63 Oph", "-0.77", "0.40", "A"}}, {{"HD 168941", "-3.76", "1.38", "A"}}, {}, {}, {{"* 9 Sgr", "0.49", "0.40", "A"}}, {}, {{"HD 165052", "0.15", "0.63", "A"}}, {{"* zet Oph", "8.91", "0.20", "A"}}, {}}

Has anibody a simpler code suggestion?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.