magislog

Web Name: magislog

WebSite: http://magislog.blogspot.com

ID:204745

Keywords:

magislog,

Description:

keywords:
description:
magislog

2013年11月25日月曜日 PHP関数stringmb_convert_kana(string$str[,string$option= "KV"[,string$encoding= mb_internal_encoding()]] )
全角を半角に変換する

$str
変換する文字列

$option
r: 全角英字を半角に変換しますR: 半角英字を全角に変換しますn: 全角数字を半角に変換しますN: 半角数字を全角に変換しますa: 全角英数字を半角に変換しますA: 半角英数字を全角に変換します "a", "A" オプションに含まれる文字はU+0022, U+0027, U+005C, U+007Eを除く U+0021 - U+007E の範囲ですs: 全角スペースを半角に変換しますU+3000 - U+0020S: 半角スペースを全角に変換しますU+0020 - U+3000k: 全角カタカナを半角カタカナに変換しますK: 半角カタカナを全角カタカナに変換しますh: 全角ひらがなを半角カタカナに変換しますH: 半角カタカナを全角ひらがなに変換しますc: 全角カタカナを全角ひらがなに変換しますC: 全角ひらがなを全角カタカナに変換しますV: 濁点付きの文字を一文字に変換します"K", "H" と共に使用します
$encoding省略した場合は 内部文字エンコーディングを使用


stringsubstr(string$string,int$start[,int$length] )

文字列stringstartで指定された位置からlengthバイト分の文字列を返します

$string
入力文字列最低 1 文字以上を指定しなければなりません

$start
start が正の場合返される文字列は string の 0 から数えて start番目から始まる文字列となります 例えば文字列'abcdef'において位置 0にある文字は'a'であり 位置2には'c'があります
start が負の場合返される文字列は stringの後ろから数えて start番目から始まる文字列となります
string の長さが start 文字以下の場合は FALSE が返されます

$length
length が指定されかつ正である場合 返される文字列は start (string の長さに依存します) から数えてlength文字数分となります
length が指定されかつ負である場合 string の終端からその文字数分の文字が省略されます (start が負の場合は 開始位置を算出したあとで) もし start が切り出し位置を超える場合 false が返されます
length が指定されかつ 0NULLもしくは FALSE であれば空の文字が返されます
length を省略した場合は start の位置から文字列の最後までの部分文字列を返します

返り値

文字列の一部を返します失敗した場合に FALSE を返しますあるいは空文字列を返します

0 件のコメント: 2013年11月24日日曜日 Python基礎リスト

sent1 = ['Call','me','Ishmael','.']
sent2 = ['NumPy','is','a','fundamental','package','needed','for','scientific','computing','with','Python.','.'];

リストの定義nltkのテキストもこのように定義されている


sent1+sent2
['Call', 'me', 'Ishmael', '.', 'NumPy', 'is', 'a', 'fundamental', 'package', 'needed', 'for', 'scientific', 'computing', 'with', 'Python.', '.']

リストは+で一緒にすることができる


sent1.append('All');
sent1
['Call', 'me', 'Ishmael', '.', 'All']

一つだけ追加したいとか用途によってはappendを使う

sent1[0]'Call'
もちろん添字も使える

sent1.index('me')1
トーケンから添字を求める場合はこう

sent1[1:3]['me', 'Ishmael']
スライシング添字のここからここまでと指定して切り出せる

文字列操作
name = "magislog" name[0]'m' name[:4]'magi'
Pythonの文字列はアレーと同じメソッドを使えるものもある

name * 2'magislogmagislog'
掛け算もできる

name + '!';'magislog!'
連結は他でもよく見る感じ


集合論:
a. { w | w V P(w) } (数式)
b. { w for w in V if p(w) } (Pythonで書くとこうなる)

これを使ってみると
from nltk.book import *
*** Introductory Examples for the NLTK Book ***
Loading text1, ..., text9 and sent1, ..., sent9
Type the name of the text or sentence to view it.
Type: 'texts()' or 'sents()' to list the materials.
text1: Moby Dick by Herman Melville 1851
text2: Sense and Sensibility by Jane Austen 1811
text3: The Book of Genesis
text4: Inaugural Address Corpus
text5: Chat Corpus
text6: Monty Python and the Holy Grail
text7: Wall Street Journal
text8: Personals Corpus
text9: The Man Who Was Thursday by G . K . Chesterton 1908
V = set(text1)
long_words = [w for w in V if len(w) 15 ]
sorted(long_words)
['CIRCUMNAVIGATION', 'Physiognomically', 'apprehensiveness', 'cannibalistically', 'characteristically', 'circumnavigating', 'circumnavigation', 'circumnavigations', 'comprehensiveness', 'hermaphroditical', 'indiscriminately', 'indispensableness', 'irresistibleness', 'physiognomically', 'preternaturalness', 'responsibilities', 'simultaneousness', 'subterraneousness', 'supernaturalness', 'superstitiousness', 'uncomfortableness', 'uncompromisedness', 'undiscriminating', 'uninterpenetratingly']




0 件のコメント: 2013年11月22日金曜日 NLTK基礎まずは練習に必要な文章をダウンロードする
import nltk
nltk.download()
よく分からなければall/all packagesで全部ダウンロードしておけば問題ないたぶん時間はかかるけど
from nltk.book import **** Introductory Examples for the NLTK Book ***Loading text1, ..., text9 and sent1, ..., sent9Type the name of the text or sentence to view it.Type: 'texts()' or 'sents()' to list the materials.text1: Moby Dick by Herman Melville 1851text2: Sense and Sensibility by Jane Austen 1811text3: The Book of Genesistext4: Inaugural Address Corpustext5: Chat Corpustext6: Monty Python and the Holy Grailtext7: Wall Street Journaltext8: Personals Corpustext9: The Man Who Was Thursday by G . K . Chesterton 1908
これでNLTKのbookモジュールからデータがロードされる
text1Text: Moby Dick by Herman Melville 1851
こうするとテキストの作者と年が表示される
text1.concordance("happy")Building index...Displaying 8 of 8 matches:, was called a Cape - Cod - man . A happy - go - lucky ; neither craven nor varivers ; through sun and shade ; by happy hearts or broken ; through all the wmost sea - terms , this one is very happy and significant . For the whale is ing by way of getting a living . Oh ! happy that the world is such an excellente says , Monsieur , that he ' s very happy to have been of any service to us ."irst love ; we marry and think to be happy for aye , when pop comes Libra , or, a desperate burglar slid into his happy home , and robbed them all of everytrous thing in his soul . That glad , happy air , that winsome sky , did at last
これでtext1からhappyを含む場所を周辺の文章と一緒に検索できる
text1.similar("happy")Building word-context index...ancient angel athirst averse chairs clear closely cold comfortedconvenient copied country curious dark discovered discreetdisinterested diverting due easy
text1でhappyと同じ文脈で使用されている単語を検索する別の文章で検索をすると同じ単語でも違う意味合いを持って使用されていることが分かる
text2.common_contexts(["happy","little"])Building word-context index...as_as so_, too_, very_, very_;
common_contextsを使うと二つ以上の単語を使われている文脈を調べることができる
text1.dispersion_plot(["happy"])


















単語が使われている位置を分散プロットで表示してくれる

text1.generate();
Building ngram index...
[ Moby Dick . That bravely and uninjured takes the mystic head again
sent it , past , present , ushered us into a large tierce or pipe ; in
fact , did die , so wildly and eagerly peering towards the forecastle
. He seems a reason in the teeth , or otherwise , of any sort ; the
whale in his hand , round the Polar bear , one way or other
circumstances , its flexions are invariably marked by various and not
from out of a clumsy left - handed man . A deep , leaving but
こうするとテキストからランダムな文章を生成するお遊び

len(text1)
260819
トークン単語の数を数える

set(text1)
set(['funereal', 'unscientific', 'divinely', 'foul', 'four', 'gag', 'prefix', 'woods', 'clotted', 'Duck', 'hanging', 'plaudits', 'woody', 'Until', 'marching', 'disobeying', 以下略
重複したトークンを除いて表示ただしまとまった文章でやると大量のトーケンで画面があふれるので注意

len(set(text1))
19317
lenとsetを組み合わせるとトークンの種類の数を調べることができる

sorted(set(text1))
['!', '!"', '!"--', "!'", '!\'"', '!)', '!)"', '!*', '!--', '!--"', "!--'", '"', '"\'', '"--', '"...', '";', '$', '', "'", "',", "',--", "'-", "'--", "';", '(', ')', '),', ')--', ').', ').--', '):', ');', ');--', '*', ',', ',"', ',"--', ",'", ",'--", ',)', ',*', ',--', ',--"'以下略

sortedをあわせるとトーケンをアルファベット順に並べてくれるなお大量の出力に注意

def lexical_diversity(text):
return len(text)/len(set(text))
lexical_diversity(text1)
13

関数の定義と呼び出しこの例では各トークンが平均何回文章中に使われているかを計算している







0 件のコメント: NLTKのインストール
Windows:
ここからNumpyをダウンロードしてインストール
ここからセットアップツールをダウンロードしてインストール
ここからmatplotlib-1.1.0をインストールバージョンに注意
pipのインストール
スタートプログラムとファイルの検索c:\Python27\Scripts\easy_installpip
PyYAMLとNLTKのインストール

スタートプログラムとファイルの検索c:\Python27\Scripts\pipinstallpyyamlnltk

なお64bitの場合セットアップツールのインストールでPython version 2.7 is required, which was not found in the registryと出て失敗する場合は32bit用のレジストリを64bit用に変更するregedit.exeを起動HKEY_LOCAL_MACHINESOFTWAREPythonを選択してエクスポート適当なファイル名で保存する保存したファイルをテキストエディターで開いてHKEY_LOCAL_MACHINE\SOFTWARE\PythonをHKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Pythonに変更ファイルを保存する保存したファイルをダブルクリックしてレジストリに変更を反映ubuntu:$sudo apt-get install python-nltk

0 件のコメント: PythonのインストールNLTKを使いたいので2.7をインストールする


Windows:Pythonの公式サイトからダウンロードしてインストール
実行全てのプログラムPython2.7IDLE
ubuntu:インストール$sudo apt-get install python2.7
実行$python2.7
動かしてみる: 9+8*7-956

0 件のコメント: ホーム登録:投稿 (Atom)ブログ アーカイブ 2013(5) 11月(5)PHP関数Python基礎NLTK基礎NLTKのインストールPythonのインストール自己紹介Unknown詳細プロフィールを表示
シンプルテーマ. Powered by Blogger.

TAGS:magislog 

<<< Thank you for your visit >>>

Websites to related :
Neo Simple Fast

  keywords:
description:
Neo Simple FastReFeatured PostAuthorLabelsCarsCityEntertainmentFashionFoodsGadgetGalleryGraphic DesignHotInfoMarkupMotion Desig

JONGMERL || Free Watch Movie Onl

  keywords:
description:
MenuAboutContactMoreMenu 1Menu 2Menu 3Menu 4MenutwitterfacebookgooglersslinkedindribbblepinterestJONGMERL || Free Watch Movie O

MOHANAD NET

  keywords:
description:
MOHANAD NETمدونة خاصة لجميع النشاطات على الانترنت وعرض الجديد في عالم السر

Test 2.4.2

  keywords:
description:
Test 2.4.2Mega Menu [Links Content]-linksMega Menu [Tabbel Style]-mtab/Fashion,Music,Foods,PeopleLatest News [Recent Post]-grip

Blogger

  keywords:
description:Google 推出的一款免费博客发布工具,可用于分享文字、照片和视频。
一个帐号,畅享 Google 所有服务! 登录并继续使用 Blogger

The Consulting Detective

  keywords:
description:
The Consulting DetectiveIm a Consulting Detective, if you can understand what that is. Here in London we have lots of governmen

Axial Racing - High End Remote C

  keywords:
description:
PRODUCTS vehicles SCX6 SCX10

Google 图书

  keywords:
description:
搜索 图片 地图 Play YouTube 新闻 Gmail 云端硬盘 更多 登录出版商简介隐私权条款帮助var f,aa=[];function ba(a){return function(){r

Solomon's words for the wise

  keywords:
description:
Solomon's words for the wisePhoto By Peggy Derr Harvest Time on Fox HillSOLOMON'S WORDS

StoltzDR. TarboxxxxSol

Trowel.com -> Offline

  keywords:
description:

Tr

ads

Hot Websites