Re: does python have the ability to detect the color of a string in SPSS syntax.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: does python have the ability to detect the color of a string in SPSS syntax.

Art Kendall
I was thinking of ways to help writers like myself be consistent in our syntax.

I thought there might be a way to grab  (1) what had already been parsed by the SE to display the syntax in the window and (2) what was in the options for coloring .  Something like "The SE has this word in bold nonitalic nonunderlined blue so according to the user's options therefore it is a command"etc. etc.

I would like to be more consistent in my casing of words in syntax.  I could look at such a list and go back and replace all such strings with a correctly cased string. 
commands:
    GET DATA
     get data
    Get Data

subcommands
 
TYPE
    type
 Type

Variables:
    Age
    AGE

    dateofbirth
    DateofBirth
    DateOfBirth

In the long run it would be useful if syntax in teaching material or emails could be colored as it is in the SE. Now it would be a very error prone process to have the syntax as text but manually colored.  Of course there are screen snips.

GET DATA /TYPE=XLSX
   /FILE= BOOK
   /SHEET=name '1988'
   /CELLRANGE=full
   /READNAMES=on
   /ASSUMEDSTRWIDTH=32767.

Takes a lot of back and forth with the mail editor
Art Kendall
Social Research Consultants
On 5/17/2013 4:30 PM, Albert-Jan Roskam [via SPSSX Discussion] wrote:
Hi Art,

In the spss install dir you can find a large amount of xml files, one for each command. These contain the command definitions (commands, subcommands, keywords, etc). Then you would still need to write a function that "tokenizes" each command in a given .sps and compares it to the relevant xml file. Why do you want to do this, if I may ask?

 
Regards,
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a
fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

From: Art Kendall <[hidden email]>
To: [hidden email]
Sent: Friday, May 17, 2013 9:56 PM
Subject: [SPSSX-L] does python have the ability to detect the color of a string inSPSS syntax.


In the syntax window coloring is  used to distinguish  commands subcommands keywords values and comments.

Is there a way to have python parse syntax and
produce a dataset with variables like color bold italic command/subcommand/keyword  word
--
Art Kendall
Social Research Consultants
Art Kendall
Social Research Consultants


View this message in context: does python have the ability to detect the color of a string inSPSS syntax.
Sent from the SPSSX Discussion mailing list archive at Nabble.com.





To start a new topic under SPSSX Discussion, email [hidden email]
To unsubscribe from SPSSX Discussion, click here.
NAML

Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: does python have the ability to detect the color of a string in SPSS syntax.

Jon K Peck
The scripting api for getting the syntax window contents just returns plain text.


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        Art Kendall <[hidden email]>
To:        [hidden email],
Date:        05/17/2013 03:48 PM
Subject:        Re: [SPSSX-L] does python have the ability to detect the color of              a string              in SPSS syntax.
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




I was thinking of ways to help writers like myself be consistent in our syntax.

I thought there might be a way to grab  (1) what had already been parsed by the SE to display the syntax in the window and (2) what was in the options for coloring .  Something like "The SE has this word in bold nonitalic nonunderlined blue so according to the user's options therefore it is a command"etc. etc.

I would like to be more consistent in my casing of words in syntax.  I could look at such a list and go back and replace all such strings with a correctly cased string.  
commands:

   GET DATA
    get data
   Get Data

subcommands

TYPE
   type
Type


Variables:
   Age
   AGE

   dateofbirth
   DateofBirth
   DateOfBirth

In the long run it would be useful if syntax in teaching material or emails could be colored as it is in the SE. Now it would be a very error prone process to have the syntax as text but manually colored.  Of course there are screen snips.

GET DATA
/TYPE=XLSX
 
/FILE= BOOK
 
/SHEET=name '1988'
 
/CELLRANGE=full
 
/READNAMES=on
  /ASSUMEDSTRWIDTH=32767.

Takes a lot of back and forth with the mail editor

Art Kendall
Social Research Consultants

On 5/17/2013 4:30 PM, Albert-Jan Roskam [via SPSSX Discussion] wrote:
Hi Art,

In the spss install dir you can find a large amount of xml files, one for each command. These contain the command definitions (commands, subcommands, keywords, etc). Then you would still need to write a function that "tokenizes" each command in a given .sps and compares it to the relevant xml file. Why do you want to do this, if I may ask?


 
Regards,
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a
fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


From: Art Kendall <[hidden email]>
To:
[hidden email]
Sent:
Friday, May 17, 2013 9:56 PM
Subject:
[SPSSX-L] does python have the ability to detect the color of a string inSPSS syntax.



In the syntax window coloring is  used to
distinguish  commands subcommands keywords values and comments.

Is there a way to have python parse syntax and
produce a dataset with variables like color bold italic command/subcommand/keyword  word

--
Art Kendall
Social Research Consultants

Art Kendall
Social Research Consultants



View this message in context: does python have the ability to detect the color of a string inSPSS syntax.
Sent from the
SPSSX Discussion mailing list archive at Nabble.com.






If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/does-python-have-the-ability-to-detect-the-color-of-a-string-inSPSS-syntax-tp5720314p5720316.html
To start a new topic under SPSSX Discussion, email [hidden email]
To unsubscribe from SPSSX Discussion,
click here.
NAML

Art Kendall
Social Research Consultants



View this message in context: Re: does python have the ability to detect the color of a string in SPSS syntax.
Sent from the
SPSSX Discussion mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: does python have the ability to detect the color of a string in SPSS syntax.

Zuluaga, Juan
In reply to this post by Art Kendall
Could this be done with the listings package in LaTeX?

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: does python have the ability to detect the color of a string in SPSS syntax.

Albert-Jan Roskam
In reply to this post by Art Kendall
>I was thinking of ways to help writers like myself be consistent in our syntax.

>
>I thought there might be a way to grab  (1) what had already been parsed by the SE to display the syntax in the window and (2) what was in the options for coloring.  Something like "The SE has this word in bold nonitalic nonunderlined blue so according to the user's options therefore it is a command"etc. etc.
>
>I would like to be more consistent in my casing of words in syntax.  I could look at such a list andgo back and replace all such strings with a correctly cased string.
>commands:
>    GET DATA
>     get data
>    Get Data


Do you know Sphinx? This is a documentation tool, based on reStructredText. One of the features is that one can easily insert properly colour-coded code snippets in the documentation. For example, PyPi.org, the site for python packages uses it, and IPython, too. Many languages are supported, e.g Python, but also SQL, Matlab, Octave, R... but not yet SPSS! To implement it, one needs to write a Pygments lexer. The lexer would know what a command is, what a subcommand, etc. The cool thing is that writing documentation is also easy, once the lexer is there.

http://sphinx-doc.org/index.html

http://pygments.org/docs/lexerdevelopment/

Last year, I did an analysis on thousands of syntaxes to make a top 100 of the most commonly used commands. For most commands I could use a simple regex, e.g. re.match("^([-+.]? *com[a-z]*) ", s, re.IGNORECASE) would be a COMPUTE command, possibly in a DO IF (preceded by +-.).
A command is often the first non-comment word after a period. But there are exceptions, e.g. in the macro language. Luckily I only needed to get a broad impression, because to get it *exactly* right is harder.


def getCommand(cmd):
    """a very crude command prettifier"""

     regex = "^%s[a-z]*) " % cmd[:3]

     m = re.match(regex, s, re.IGNORECASE)
     if m:
         return allCmds.get(m.group(1), cmd)

     return cmd

>subcommands
> TYPE
>    type
> Type
>
>Variables:
>    Age
>    AGE
>
>    dateofbirth
>    DateofBirth
>    DateOfBirth
>
>In the long run it would be useful if syntax in teaching material or emails could be colored as it is in the SE. Now it would be a very error prone process to have the syntax as text but manually colored.  Of course there are screen snips.
>
>GET DATA /TYPE=XLSX
>   /FILE= BOOK
>   /SHEET=name '1988'
>   /CELLRANGE=full
>  /READNAMES=on
>   /ASSUMEDSTRWIDTH=32767.
>
>Takes a lot of back and forth with the mail editor
>
>Art Kendall
Social Research Consultants
On 5/17/2013 4:30 PM, Albert-Jan Roskam [via SPSSX Discussion] wrote:
>
>Hi Art,
>>
>>In the spss install dir you can find a large amount of xml
        files, one for each command. These contain the command
        definitions (commands, subcommands, keywords, etc). Then you
        would still need to write a function that "tokenizes" each
        command in a given .sps and compares it to the relevant xml
        file. Why do you want to do this, if I may ask?

>>
>>
>>
>>
>>Regards,
>>Albert-Jan
>>
>>
>>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>All right, but apart from the sanitation, the medicine,
          education, wine, public order, irrigation, roads, a
>>fresh water system, and public health, what have the Romans
          ever done for us?

>>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>
>>
>>>________________________________
>>> From: Art Kendall <[hidden email]>
>>>To: [hidden email]
>>>Sent: Friday, May 17, 2013 9:56 PM
>>>Subject: [SPSSX-L] does python have the ability to detect the color of a string inSPSS syntax.
>>>
>>>
>>>
>>>
>>>In the syntax window coloring is  used to distinguish  commands subcommands keywords values and comments.
>>>
>>>Is there a way to have python parse syntax and
>>>produce a dataset with variables like color bold
                    italic command/subcommand/keyword  word
>>>
>>>--
Art Kendall
Social Research Consultants

>>>Art Kendall
>>>Social Research Consultants
>>>>>>________________________________
>>> View this message in context: does python have the ability to detect the color of a string inSPSS syntax.
>>>Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>>>
>>>
>>>
>>
>>>>________________________________
>>
>>If you reply to this email, your message will be added to the discussion below:http://spssx-discussion.1045642.n5.nabble.com/does-python-have-the-ability-to-detect-the-color-of-a-string-inSPSS-syntax-tp5720314p5720316.html
>>To start a new topic under SPSSX Discussion, email [hidden email]
>>To unsubscribe from SPSSX Discussion, click here.
>>NAML
>
>Art Kendall
>Social Research Consultants
>>________________________________
> View this message in context: Re: does python have the ability to detect the color of a string in SPSS syntax.
>Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD