from nltk.stem.wordnet import WordNetLemmatizer l = WordNetLemmatizer() l.lemmatize('cars') # car l.lemmatize('women') # woman l.lemmatize('fantasized','v') # fantasizeSo, a word will be checked with wordnet to see its basic form according to part of speech.
Pages
Profile
|
Hi, I'm Veerapat Sriarunrungrueang, an expert in technology field, especially full stack web development and performance testing.This is my coding diary. I usually develop and keep code snippets or some tricks, and update to this diary when I have time.
Nowadays, I've been giving counsel to many well-known firms in Thailand.
view more... |
Tuesday, December 28, 2010
How to Lemmatization with Wordnet in NLTK
We can convert a word back to its basic form by using wordnet lemmatizer. Moreover, we can specific part of speech to check its form: n->noun, v->verb, a->adjective, r->adverb (if not specify, it will be noun).
Labels:
NLP,
NLTK,
Programming,
Python
Monday, December 27, 2010
What's the difference between list and tuples in Python?
The key difference is tuple is immutable but list is not. So, tuple can be used as a key in dictionary and get more slight performance and tuple has a structure but list has a order.
Labels:
Programming,
Python
Thursday, December 23, 2010
Wordnet Interface in Python with NLTK
Currently, my project involves with natural language processing and also wordnet for seeing the relationship between word meanings. In python, wordnet can be used with NLTK. NLTK has a wordnet of Princeton University.The main features that are supported in NLTK as following: synset, lemma, hypernym, hyponym, antonym and path similarity.
Basic use examples:
See more details at:
http://nltk.googlecode.com/svn/trunk/doc/howto/wordnet.html
http://wordnet.princeton.edu/
Basic use examples:
import nltk from nltk import wordnet as wn #looking word's synsets wn.synsets('beautiful') #synsets car = wn.synset('car.n.01') car.lemmas car.hypernyms() car.hyponyms() #antonyms car.lemmas[0].antonyms()
See more details at:
http://nltk.googlecode.com/svn/trunk/doc/howto/wordnet.html
http://wordnet.princeton.edu/
Labels:
NLP,
NLTK,
Programming,
Python
Sunday, December 12, 2010
How to make object support indexing in python (object[index])
Sometime, we may want the object can do like array or dict that use object[index] instead of object.getsomthing() for making it more convenience. So, the solution is easy, python provide us the attribute for creating object support indexing that is "__getitem__(key)".
For example
More information about python attributes at: http://docs.python.org/reference/datamodel.html
For example
class Test: def __getitem__(self,key): return 0 a = Test() print a[2] print a["hello"]We can modify its behavior in the method.
More information about python attributes at: http://docs.python.org/reference/datamodel.html
Labels:
Programming,
Python
Saturday, December 11, 2010
Beginning with Text to Speech in Android
For this post, my motivation came from creating a program to speak some books. So, I need text to speech.
Then, I found these two resources from android site which are very interesting and easy to understand. Those two links are as following:
http://android-developers.blogspot.com/2009/09/introduction-to-text-to-speech-in.html
http://android-developers.blogspot.com/2010/03/speech-input-api-for-android.html
Two sites can help you to begin with text to speech in android .
Enjoy ^^
Then, I found these two resources from android site which are very interesting and easy to understand. Those two links are as following:
http://android-developers.blogspot.com/2009/09/introduction-to-text-to-speech-in.html
http://android-developers.blogspot.com/2010/03/speech-input-api-for-android.html
Two sites can help you to begin with text to speech in android .
Enjoy ^^
Labels:
Android,
Programming
How to check subclass in python
An object oriented in python is different from full-support object oriented like java or etc. To check subclass, we need to use built-in function from python called "issubclass"
Ok, let's begin with issubclass(class, classinfo).
It is easy right? ^^
Ok, let's begin with issubclass(class, classinfo).
class A(object): pass class B(A): pass a = A() b = B() print issubclass(a.__class__,A) print issubclass(b.__class__,B)
It is easy right? ^^
Labels:
Programming,
Python
Wednesday, December 1, 2010
How to get current Date/Time in Python
In my project, sometimes I have to used current date to compare. So, we need to get date from the system.
import datetime dt = datetime.datetime.now() print dt.year print dt.month print dt.day print dt.hour print dt.minute print dt.secondVery easy right ^^
Labels:
Programming,
Python
Divinity 2: Statue Puzzle at Keara’s Headquarters
Divinity 2 is an interesting game for me in the story and game play. While I playing this game, I feel I'm in the game. The broad story is very simple. It's the story between dragon knight and dragon slayer. And once our character will be a dragon slayer who hunt the dragons but ,by chance, our character will be a dragon knight. And both sides become our opponents.
So far, I walk to Keara's Headquaters, and face with the puzzle problems in the games. I'm interested in this puzzle about how the creator think this puzzle? for me, it's very hard to solve it.
There 5 five statues. We have to identify their names to open the last door in order to fight with Keara.
There are 2 types of statue. First one will be statue with the fire blades, another one will be statue with the blades.
I will give 5 statues into the number of 1, 2, 3, 4 and 5 for easy understanding.
There are 5 five names: Mayhem, Chaos, Devastation, Havoc, Waste.
The first room, (1) stay alone and it's a fire blades type.
The second room, (2), (3) stay together. (2) is a blades and (3) is a fire blades.
The third room, (4), (5) stay together. (4) is a fire blades and (5) is a blades.
Each statue will give us clues.
(1) hints: Mayhem is not in the same room as Havoc. Devastation is in
the same room as Chaos.
(2) hints: I am either Devastation or Chaos. Waste is in the same room
as Mayhem.
(3) hints: Mayhem is alone in his room. Havoc is in this room.
(4) hints: I am neither Chaos, nor Havoc. Chaos is neither in my room,
nor in Waste's.
(5) hints: I am in the same room as Waste. I am neither Mayhem, nor
Waste.
We have to identify each statue name with those hints. At last, I can pass but take a long time - -".
Hope that it can help ^^
So far, I walk to Keara's Headquaters, and face with the puzzle problems in the games. I'm interested in this puzzle about how the creator think this puzzle? for me, it's very hard to solve it.
There 5 five statues. We have to identify their names to open the last door in order to fight with Keara.
There are 2 types of statue. First one will be statue with the fire blades, another one will be statue with the blades.
I will give 5 statues into the number of 1, 2, 3, 4 and 5 for easy understanding.
There are 5 five names: Mayhem, Chaos, Devastation, Havoc, Waste.
The first room, (1) stay alone and it's a fire blades type.
The second room, (2), (3) stay together. (2) is a blades and (3) is a fire blades.
The third room, (4), (5) stay together. (4) is a fire blades and (5) is a blades.
Each statue will give us clues.
(1) hints: Mayhem is not in the same room as Havoc. Devastation is in
the same room as Chaos.
(2) hints: I am either Devastation or Chaos. Waste is in the same room
as Mayhem.
(3) hints: Mayhem is alone in his room. Havoc is in this room.
(4) hints: I am neither Chaos, nor Havoc. Chaos is neither in my room,
nor in Waste's.
(5) hints: I am in the same room as Waste. I am neither Mayhem, nor
Waste.
We have to identify each statue name with those hints. At last, I can pass but take a long time - -".
Hints: Some sentences are lying, we have to change them into opposite way.
Answer: (1) is Devastation, (2) is Waste, (3) is Chaos, (4) is Havoc, and (5) is Mayhem.
(Drag over to see hints and answer.)Hope that it can help ^^
Labels:
Game
Subscribe to:
Posts (Atom)