Python 2.7 : Why MyOutput Word Tokenize in alphabet not in word
I did word tokenize from text file(token.txt), the content are
best hotel great food many facilities kids family near city center comfortable room . room big luxurious even deluxe type breakfast many variant choosen .best hotel great food many facilities kids family near city center comfortable room .
before this,i did stopword removal,remove punctual and remove unnecessary word.
then i did word tokenizing and write to file using code :
import codecs
import nltk
from nltk import sent_tokenize,word_tokenize,pos_tag
fname = "token.txt"
file_object = open("tokenres.txt", 'w')
with codecs.open(fname, 'r',"latin-1") as f:
for line in f:
tweet = f.readlines()
tokenized_sents = [word_tokenize(i) for i in tweet]
for i in tokenized_sents:
file_object.write(str(i))
file_object.close()
Using that code, there were no result.file tokenres.txt still empty.
But if i use this code :
with codecs.open(fname, 'r',"latin-1") as f:
for line in f:
tweet = f.read()
tokenized_sents = [word_tokenize(i) for i in line]
for i in tokenized_sents:
file_object.write(str(i))
file_object.close()
The Output can write in file tokenres.txt. Not word by word, but alphabet per alphabet the token result like this.
[u'b'][u'e'][u's'][u't'][u'h'][u'o'][u't'][u'e'][u'l'][u'g'][u'r'][u'e'][u'a'][u't'][u'f'][u'o'][u'o'][u'd'][u'm'][u'a'][u'n'][u'y'][u'f'][u'a'][u'c'][u'i'][u'l'][u'i'][u't'][u'i'][u'e'][u's'][u'k'][u'i'][u'd'][u's'][u'f'][u'a'][u'm'][u'i'][u'l'][u'y'][u'n'][u'e'][u'a'][u'r'][u'c'][u'i'][u't'][u'y'][u'c'][u'e'][u'n'][u't'][u'e'][u'r'][u'c'][u'o'][u'm'][u'f'][u'o'][u'r'][u't'][u'a'][u'b'][u'l'][u'e'][u'r'][u'o']
How can i solve this to make right tokenize output, for pos tagging ?. And after tokenize im going to do Pos Tagging from file tokenres.txt.
python python-2.7
add a comment |
I did word tokenize from text file(token.txt), the content are
best hotel great food many facilities kids family near city center comfortable room . room big luxurious even deluxe type breakfast many variant choosen .best hotel great food many facilities kids family near city center comfortable room .
before this,i did stopword removal,remove punctual and remove unnecessary word.
then i did word tokenizing and write to file using code :
import codecs
import nltk
from nltk import sent_tokenize,word_tokenize,pos_tag
fname = "token.txt"
file_object = open("tokenres.txt", 'w')
with codecs.open(fname, 'r',"latin-1") as f:
for line in f:
tweet = f.readlines()
tokenized_sents = [word_tokenize(i) for i in tweet]
for i in tokenized_sents:
file_object.write(str(i))
file_object.close()
Using that code, there were no result.file tokenres.txt still empty.
But if i use this code :
with codecs.open(fname, 'r',"latin-1") as f:
for line in f:
tweet = f.read()
tokenized_sents = [word_tokenize(i) for i in line]
for i in tokenized_sents:
file_object.write(str(i))
file_object.close()
The Output can write in file tokenres.txt. Not word by word, but alphabet per alphabet the token result like this.
[u'b'][u'e'][u's'][u't'][u'h'][u'o'][u't'][u'e'][u'l'][u'g'][u'r'][u'e'][u'a'][u't'][u'f'][u'o'][u'o'][u'd'][u'm'][u'a'][u'n'][u'y'][u'f'][u'a'][u'c'][u'i'][u'l'][u'i'][u't'][u'i'][u'e'][u's'][u'k'][u'i'][u'd'][u's'][u'f'][u'a'][u'm'][u'i'][u'l'][u'y'][u'n'][u'e'][u'a'][u'r'][u'c'][u'i'][u't'][u'y'][u'c'][u'e'][u'n'][u't'][u'e'][u'r'][u'c'][u'o'][u'm'][u'f'][u'o'][u'r'][u't'][u'a'][u'b'][u'l'][u'e'][u'r'][u'o']
How can i solve this to make right tokenize output, for pos tagging ?. And after tokenize im going to do Pos Tagging from file tokenres.txt.
python python-2.7
add a comment |
I did word tokenize from text file(token.txt), the content are
best hotel great food many facilities kids family near city center comfortable room . room big luxurious even deluxe type breakfast many variant choosen .best hotel great food many facilities kids family near city center comfortable room .
before this,i did stopword removal,remove punctual and remove unnecessary word.
then i did word tokenizing and write to file using code :
import codecs
import nltk
from nltk import sent_tokenize,word_tokenize,pos_tag
fname = "token.txt"
file_object = open("tokenres.txt", 'w')
with codecs.open(fname, 'r',"latin-1") as f:
for line in f:
tweet = f.readlines()
tokenized_sents = [word_tokenize(i) for i in tweet]
for i in tokenized_sents:
file_object.write(str(i))
file_object.close()
Using that code, there were no result.file tokenres.txt still empty.
But if i use this code :
with codecs.open(fname, 'r',"latin-1") as f:
for line in f:
tweet = f.read()
tokenized_sents = [word_tokenize(i) for i in line]
for i in tokenized_sents:
file_object.write(str(i))
file_object.close()
The Output can write in file tokenres.txt. Not word by word, but alphabet per alphabet the token result like this.
[u'b'][u'e'][u's'][u't'][u'h'][u'o'][u't'][u'e'][u'l'][u'g'][u'r'][u'e'][u'a'][u't'][u'f'][u'o'][u'o'][u'd'][u'm'][u'a'][u'n'][u'y'][u'f'][u'a'][u'c'][u'i'][u'l'][u'i'][u't'][u'i'][u'e'][u's'][u'k'][u'i'][u'd'][u's'][u'f'][u'a'][u'm'][u'i'][u'l'][u'y'][u'n'][u'e'][u'a'][u'r'][u'c'][u'i'][u't'][u'y'][u'c'][u'e'][u'n'][u't'][u'e'][u'r'][u'c'][u'o'][u'm'][u'f'][u'o'][u'r'][u't'][u'a'][u'b'][u'l'][u'e'][u'r'][u'o']
How can i solve this to make right tokenize output, for pos tagging ?. And after tokenize im going to do Pos Tagging from file tokenres.txt.
python python-2.7
I did word tokenize from text file(token.txt), the content are
best hotel great food many facilities kids family near city center comfortable room . room big luxurious even deluxe type breakfast many variant choosen .best hotel great food many facilities kids family near city center comfortable room .
before this,i did stopword removal,remove punctual and remove unnecessary word.
then i did word tokenizing and write to file using code :
import codecs
import nltk
from nltk import sent_tokenize,word_tokenize,pos_tag
fname = "token.txt"
file_object = open("tokenres.txt", 'w')
with codecs.open(fname, 'r',"latin-1") as f:
for line in f:
tweet = f.readlines()
tokenized_sents = [word_tokenize(i) for i in tweet]
for i in tokenized_sents:
file_object.write(str(i))
file_object.close()
Using that code, there were no result.file tokenres.txt still empty.
But if i use this code :
with codecs.open(fname, 'r',"latin-1") as f:
for line in f:
tweet = f.read()
tokenized_sents = [word_tokenize(i) for i in line]
for i in tokenized_sents:
file_object.write(str(i))
file_object.close()
The Output can write in file tokenres.txt. Not word by word, but alphabet per alphabet the token result like this.
[u'b'][u'e'][u's'][u't'][u'h'][u'o'][u't'][u'e'][u'l'][u'g'][u'r'][u'e'][u'a'][u't'][u'f'][u'o'][u'o'][u'd'][u'm'][u'a'][u'n'][u'y'][u'f'][u'a'][u'c'][u'i'][u'l'][u'i'][u't'][u'i'][u'e'][u's'][u'k'][u'i'][u'd'][u's'][u'f'][u'a'][u'm'][u'i'][u'l'][u'y'][u'n'][u'e'][u'a'][u'r'][u'c'][u'i'][u't'][u'y'][u'c'][u'e'][u'n'][u't'][u'e'][u'r'][u'c'][u'o'][u'm'][u'f'][u'o'][u'r'][u't'][u'a'][u'b'][u'l'][u'e'][u'r'][u'o']
How can i solve this to make right tokenize output, for pos tagging ?. And after tokenize im going to do Pos Tagging from file tokenres.txt.
python python-2.7
python python-2.7
edited Nov 26 '18 at 14:44
Ivan Kolesnikov
1,26111032
1,26111032
asked Nov 23 '18 at 7:59
Wahyu Wahyu
11
11
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53442684%2fpython-2-7-why-myoutput-word-tokenize-in-alphabet-not-in-word%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53442684%2fpython-2-7-why-myoutput-word-tokenize-in-alphabet-not-in-word%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown