Affichage des articles dont le libellé est partie technique. Afficher tous les articles
Affichage des articles dont le libellé est partie technique. Afficher tous les articles

samedi 24 mars 2012

INTEX, UNITEX, NOOJ

Some technologies I'd never heard of but probably should have:

Unitex - a corpus-processing system

Nooj - a linguistic development environment

INTEX  - a linguistic development environment

vendredi 16 mars 2012

Twitter-scraping with Python for Dummies (in Windows)

I'm ok with Python but it took me a while to get this set up, and all the "easy guides" seem to start from Linux.
Compiled from a couple of pages, and some trial and error.


You will need:




Step 1: Get your Twitter Api key
You will need to be a twitter user to get an api key. You will need an api key for some of the things you'll do later. You don't absolutely need to do this step right now but it's probably eaiser.
This explains the process pretty clearly When you're filling out the form, it doesn't matter what you put in the fields for "app name" and "website", etc.
You will also need the access token, so click on the button at the bottom of the page to get that.

Also, go into your settings (there should be a tab at the top of the page), scroll down to 'Application Type' and choose 'Read and Write'. This will mean you can update your twitter status, and things like that. (Then, obviously, scroll down and click on 'Update this Twitter application's settings')
If you'd already created your access token before doing this, you will need to re-do that to update it with the new permissions. Click 'Recreate my access token'.


Step 2: Download the python wrapper for the twitter api and its dependencies 
Open up a Command Prompt
( Start->Accessories->Command Prompt )
Type: cd c:\Python27\scripts  

Type:  easy_install simplejson
(wait. read what's on the screen - hopefully not an error)

Type: easy_install httplib2
(wait, etc)

Type: easy_install oauth2
(wait, etc)


Type: easy_install twitter
(wait, etc - and if that doesn't work, try: easy_install pip
then: pip install twitter )


You should now be good to go.



Step 2: Setting up the twitter api wrapper in python
Open up a Python shell window. You should get this if you go :
Start -> Programs -> Python27 -> IDLE (Python Gui)
It should look like this:


Type:  import twitter
(nothing happens)

Type: api = twitter.Api()
(nothing happens)

We're now referring to the official documentation here.

Type:  
api = twitter.Api(consumer_key='consumer_key', 
consumer_secret='consumer_secret', 
access_token_key='access_token', 
access_token_secret='access_token_secret')
- Except that where it says 'consumer_secret', 'access_token', etc (everything with the single quote marks), write in the Consumer Key / Consumer Secret / etc that you got in Step 1. Keep the quote marks.
Also, you don't need to press Enter between these lines, but it doesn't matter if you do.

To check that that has worked, type:
print api.VerifyCredentials()
When you press Enter you should get a bunch of text (hopefully not any errors).

What would be a good idea right now is to save this script, so that you don't have to go back and remember/retype all of that next time you want to work.
(In the Python Shell window,  File->Save)


Step 4: Try a few things out
(These are from the Google Code page):


allstatuses = api.GetPublicTimeline()
print [s.user.name for s in statuses]


statuses = api.GetUserTimeline("user")
(The username is text, so must be in quote marks)

friends = api.GetFriends("user")
print [f.name for f in friends]
(For list of people the user is "following")


and... away you go. full documentation here.

jeudi 6 octobre 2011

les donnees


Nous avons affaire à des données semi-structurés - ce qui doit simplifier la tâche de nettoyage. 



Examinons en plus de détail la forme, en prenant quelques exemples tirés du twitter de la chanteuse anglaise Lily Allen.


La forme d'un tweet le plus simple sera simplement du texte, avec, éventuellement, un hashtag.




  • <div class="tweet-text js-tweet-text">Just worked out that I've watched 10.5 full days of ER over the past 6 weeks. <a href="/#!/search?q=%23gross" title="#gross" class=" twitter-hashtag pretty-link" rel="nofollow"><s class="hash">#</s><b>gross</b></a></div>




En fait, le code entier pour un tweet sera :

<div class="js-stream-item stream-item" data-item-id="121529889751973888" data-item-type="tweet" media="true">
    <div class="more">»</div>
<div class="stream-item-content tweet js-actionable-tweet js-stream-tweet stream-tweet  " data-is-reply-to="false" data-tweet-id="121529889751973888" data-item-id="121529889751973888" data-screen-name="MrsLRCooper" data-user-id="16998020">
  <div class="tweet-dogear"></div>
  <div class="tweet-image">
      <img height="48" width="48" src="http://a0.twimg.com/profile_images/1101333870/lily_allen_420-420x0_normal.jpg" alt="lilyrosecooper" class="user-profile-link" data-user-id="16998020">
  </div>
  <div class="tweet-content">
    <div class="tweet-row">
              <span class="tweet-user-name">
  <a class="tweet-screen-name user-profile-link" data-user-id="16998020" href="/#!/MrsLRCooper" title="lilyrosecooper">MrsLRCooper</a>
  <span class="tweet-full-name">lilyrosecooper</span>
  </span>
      <div class="tweet-corner">
        <div class="tweet-meta">
  <span class="icons">
                  <div class="extra-icons">
              <span class="inlinemedia-icons js-icon-container"></span>
        </div>
  </span>
</div>
      </div>
    </div>
    <div class="tweet-row">
      <div class="tweet-text js-tweet-text">Just worked out that I've watched 10.5 full days of ER over the past 6 weeks. <a href="/#!/search?q=%23gross" title="#gross" class="  twitter-hashtag pretty-link" rel="nofollow"><s class="hash">#</s><b>gross</b></a></div>
    </div>
          <div class="tweet-row">
        <a href="/#!/MrsLRCooper/status/121529889751973888" class="tweet-timestamp" title="12:19 PM Oct 5th"><span class="_old-timestamp" data-time="1317809958000" data-long-form="true">5 Oct</span></a>
        <span class="tweet-actions js-actions" data-tweet-id="121529889751973888">
  </span>
      </div>
          </div>
</div>
  
</div>



Mais pour l'instant nous pouvons regarder simplement le <div class="tweet-text js-tweet-text"> , qui contient le texte.




Nous avons aussi des tweets avec une référence "@" :

  • <div class="tweet-text js-tweet-text"><a class=" twitter-atreply pretty-link" data-screen-name="eddychemical" href="/#!/eddychemical" rel="nofollow"><s>@</s><b>eddychemical</b></a> LOLZ !!!!!!!!!</div>
Enfin, le codeage de "@" en soi n'est pas plus compliqué que pour les hashtags.


Des liens liens hyper-textes - pareil :


  • <div class="tweet-text js-tweet-text">Heey check this out, it's <a class="  twitter-atreply pretty-link" data-screen-name="Charliecondou" href="/#!/Charliecondou" rel="nofollow"><s>@</s><b>Charliecondou</b></a> <a href="http://t.co/jQBQmqz1" data-expanded-url="http://www.guardian.co.uk/lifeandstyle/2011/oct/01/coronation-street-charlie-condou-gay-dad?INTCMP=SRCH" title="http://www.guardian.co.uk/lifeandstyle/2011/oct/01/coronation-street-charlie-condou-gay-dad/?INTCMP=SRCH" target="_blank" rel="nofollow" class="twitter-timeline-link" data-ultimate-url="http://www.guardian.co.uk/lifeandstyle/2011/oct/01/coronation-street-charlie-condou-gay-dad/?INTCMP=SRCH">guardian.co.uk/lifeandstyle/2…</a></div>


La seule chose qui diffère beaucoup des ces exemples est les re-tweets :




(Mais je re-edit ce poste plus tard, et, suite à la perte de mon ordinateur, je n'ai plus le code pour ce tweet)


Néanmoins, tout ça, c'est en partant du code html du page web (qui pourrait être obtenu par une méthode assez manuelle). L'autre possibilité c'est de se plonger dans l'api...