SlideShare uma empresa Scribd logo
1 de 33
Baixar para ler offline
テキストファイルの話
・   文字化けで読めないページがある
・   受け取った文書ファイルが開けない
・   ウムラウト記号が壊れた
・   「髙橋」という入力が弾かれた
・   ①って書いたら怒られた
・   etc.

→なんで?
  どういう原理で?
001100010011100000101110001000000100100001100101011011100110001101100101001000000111010001101
000011001010010000001110011011000010111100101101001011011100110011100111010001000000010000001
                                                               とあるファイル
001001011001100010000001111001011011110111010100100000011010110110111001101111011101110010000
001110100011010000110010100100000011001010110111001100101011011010111100100001101000010100010
000000100000001000000010000001100001011011100110010000100000011010110110111001101111011101110
010000001111001011011110111010101110010011100110110010101101100011001100010110000100000011110
010110111101110101001000000110111001100101011001010110010000100000011011100110111101110100001
000000110011001100101011000010111001000100000011101000110100001100101001000000111001001100101
011100110111010101101100011101000010000001101111011001100010000001100001000011010000101000100
000001000000010000000100000011010000111010101101110011001000111001001100101011001000010000001
100010011000010111010001110100011011000110010101110011001011100010000000100000010010010110011
000100000011110010110111101110101001000000110101101101110011011110111011100100000011110010110
111101110101011100100111001101100101011011000110011000100000011000100111010101110100001000000
110111001101111011101000010000001110100011010000110010100100000011001010110111001100101011011
010111100100101100000011010000101000100000001000000010000000100000011001100110111101110010001
000000110010101110110011001010111001001111001001000000111011001101001011000110111010001101111
011100100111100100100000011001110110000101101001011011100110010101100100001000000111100101101
111011101010010000001110111011010010110110001101100001000000110000101101100011100110110111100
100000011100110111010101100110011001100110010101110010001000000110000100100000011001000110010
101100110011001010110000101110100001011100010000000001101000010100010000000100000001000000010
000001001001011001100010000001111001011011110111010100100000011010110110111001101111011101110
010000001101110011001010110100101110100011010000110010101110010001000000111010001101000011001
010010000001100101011011100110010101101101011110010010000001101110011011110111001000100000011
110010110111101110101011100100111001101100101011011000110011000101100001000000111100101101111
011101010010000001110111011010010110110001101100000011010000101000100000001000000010000000100
000011100110111010101100011011000110111010101101101011000100010000001101001011011100010000001
100101011101100110010101110010011110010010000001100010011000010111010001110100011011000110010
1001011100000110100001010
00110001   00111000   00101110   00100000   01001000   01100101   01101110   01100011   01100101   00100000   01110100
01101000   01100101   00100000   01110011   01100001   01111001   01101001   01101110   01100111   00111010   00100000
00100000   01001001   01100110   00100000   01111001   01101111   01110101   00100000   01101011   01101110   01101111
01110111   00100000   01110100   01101000   01100101   00100000   01100101   01101110   01100101   01101101   01111001
00001101   00001010   00100000   00100000   00100000   00100000   01100001   01101110   01100100   00100000   01101011
01101110   01101111   01110111   00100000   01111001   01101111   01110101   01110010   01110011   01100101   01101100
01100110   00101100   00100000   01111001   01101111   01110101   00100000   01101110   01100101   01100101   01100100
00100000   01101110   01101111   01110100   00100000   01100110   01100101   01100001   01110010   00100000   01110100
01101000   01100101   00100000   01110010   01100101   01110011   01110101   01101100   01110100   00100000   01101111
01100110   00100000   01100001   00001101   00001010   00100000   00100000   00100000   00100000   01101000   01110101
01101110   01100100   01110010   01100101   01100100   00100000   01100010   01100001   01110100   01110100   01101100
01100101   01110011   00101110   00100000   00100000   01001001   01100110   00100000   01111001   01101111   01110101
00100000   01101011   01101110   01101111   01110111   00100000   01111001   01101111   01110101   01110010   01110011
01100101   01101100   01100110   00100000   01100010   01110101   01110100   00100000   01101110   01101111   01110100
00100000   01110100   01101000   01100101   00100000   01100101   01101110   01100101   01101101   01111001   00101100
00001101   00001010   00100000   00100000   00100000   00100000   01100110   01101111   01110010   00100000   01100101
01110110   01100101   01110010   01111001   00100000   01110110   01101001   01100011   01110100   01101111   01110010
01111001   00100000   01100111   01100001   01101001   01101110   01100101   01100100   00100000   01111001   01101111
01110101   00100000   01110111   01101001   01101100   01101100   00100000   01100001   01101100   01110011   01101111
00100000   01110011   01110101   01100110   01100110   01100101   01110010   00100000   01100001   00100000   01100100
01100101   01100110   01100101   01100001   01110100   00101110   00100000   00001101   00001010   00100000   00100000
00100000   00100000   01001001   01100110   00100000   01111001   01101111   01110101   00100000   01101011   01101110
01101111
01110100   8桁に区切ってみる
           01110111
           01101000
                      00100000
                      01100101
                                 01101110
                                 00100000
                                            01100101
                                            01100101
                                                       01101001
                                                       01101110
                                                                  01110100
                                                                  01100101
                                                                             01101000
                                                                             01101101
                                                                                        01100101
                                                                                        01111001
                                                                                                   01110010
                                                                                                   00100000
                                                                                                              00100000
                                                                                                              01101110
01101111   01110010   00100000   01111001   01101111   01110101   01110010   01110011   01100101   01101100   01100110
00101100   00100000   01111001   01101111   01110101   00100000   01110111   01101001   01101100   01101100   00001101
00001010   00100000   00100000   00100000   00100000   01110011   01110101   01100011   01100011   01110101   01101101
01100010   00100000   01101001   01101110   00100000   01100101   01110110   01100101   01110010   01111001   00100000
01100010   01100001   01110100   01110100   01101100   01100101   00101110   00001101   00001010
00110111


八つの 0/1 の並び方は、
全部で256通りある
49 56 46 32 72 101 110 99 101 32 116 104 101 32 115 97 121 105 110 103 58 32
32 73 102 32 121 111 117 32 107 110 111 119 32 116 104 101 32 101 110 101
109 121 13 10 32 32 32 32 97 110 100 32 107 110 111 119 32 121 111 117 114
115 101 108 102 44 32 121 111 117 32 110 101 101 100 32 110 111 116 32 102
101 97 114 32 116 104 101 32 114 101 115 117 108 116 32 111 102 32 97 13 10
32 32 32 32 104 117 110 100 114 101 100 32 98 97 116 116 108 101 115 46 32
32 73 102 32 121 111 117 32 107 110 111 119 32 121 111 117 114 115 101 108
102 32 98 117 116 32 110 111 116 32 116 104 101 32 101 110 101 109 121 44 13
10 32 32 32 32 102 111 114 32 101 118 101 114 121 32 118 105 99 116 111 114
121 32 103 97 105 110 101 100 32 121 111 117 32 119 105 108 108 32 97 108
115 111 32 115 117 102 102 101 114 32 97 32 100 101 102 101 97 116 46 32 13
10 32 32 32 32 73 102 32 121 111 117 32 107 110 111 119 32 110 101 105 116
104 101 114 32 116 104 101 32 101 110 101 109 121 32 110 111 114 32 121 111
117 114 115 101 108 102 44 32 121 111 117 32 119 105 108 108 13 10 32 32 32
32 115 117 99 99 117 109 98 32 105 110 32 101 118 101 114 121 32 98 97 116
116 108 101 46 13 10



                     さっきの8桁づつを、
                     対応する数字に直す
ASCII表

 という変換ルール




0~31は制御文字。
たとえば10とか13は
改行をあらわす
18. Hence the saying: If you know the enemy
    and know yourself, you need not fear the result of a
    hundred battles. If you know yourself but not the enemy,
    for every victory gained you will also suffer a defeat.
    If you know neither the enemy nor yourself, you will
    succumb in every battle.




            故に曰わく、彼れを知りて己れを知れば、百戦して殆うからず。彼れを知
            らずし て己れを知れば、一勝一負す。彼れを知らず己れを知らざれば、
            戦う毎に必らず殆うし。 (岩波文庫『孫子の兵法』から引用)


            英文は、『Project Gutenberg』 より
日本語の文字は、256通りでは
 表現できない。
 常用漢字だけでも 1,945文字



カナ ダケ ヲ ヒョウジ サセテ 256 トオリ ニ オシコンダ コトモ アッタケド
それじゃあ、0~256を二つあわせて
一文字ってことにすれば?

[49 56] [46 32] [72 101] [110 99] …
 山     本     哲    也    とかいった風に。

これなら 256の2乗 = 65,536 文字まで表せそう…


今まで書いてきたASCII文書との
互換性がなくなっちゃうからダメ
0~127 が来たらASCII、
128~255が来たら「次とあわせて」
日本語とみなす。

49 56 46 32 72 [201 220] 99 …
 a b c d e ^^^^^^^^
                 ここだけ日本語(1文字)

これなら、ASCII文字とその他の日本語も共存できそう。
ASCII文書に日本語を混ぜるための
具体的なルールが、
シフトJIS とか、EUC とか呼ばれるもの
。
エンコーディングともいう。

一種類で済んでいればよかったのに。
シフトJIS
0~127が来たら、ASCIIと同じ文字。
129~159 または 224~239 が来たら、
 次のデータをくっつけて日本語文字のどれかにあてる。
160~223は、半角カナというものにあてられる。
「あ」を表すデータは、130, 160。

EUC(日本語EUC)
0~127が来たら、ASCIIと同じ文字。
160~255が来たら、次のデータをくっつけて日本語文字の
 どれかにあてる。
143が来たら、次のデータは半角カナという目印。
「あ」を表すデータは、164, 162。
シフトJIS で書いたつもりのファイルを
  EUCと間違えて解読したら…

13 10 32 32 137 186 139   シフトJISかな?
76 130 204 151 118 151
204 130 201 130 168 130
162 130 196 129 67 13
10 129 117 144 125 143
145 138 217 144 69 136
                                      アタリ
245 139 179 136 231 131
118 131 141 131 79 131
137 131 128 40 73 84
140 164 143 67 41 129
118 130 240 13 10 142
192 142 123 130 162 130
189 130 181 130 220 130
183 129 66 13 10 13 10     EUCかな?
 13 10




                                      ハズレ
「エンコーディング」と、「文字セット」
という概念

       使える文字一覧(文字セット)※符号化文字集合とも言うんだって




                   これらの文字からチョイスして、
  abcABC           データの並びに落とすルールが
                   エンコーディング
  012345
  亜阿唖…

              本 日 は 晴 天 な り …
              13 10 32 32 137 186 139 76 130 204 151 …
文字セットとして主に知っているべきもの

JIS(JISX0208、6897字)
制定後に多少の変動があったが、最終バージョンではこれ?
JIS第一水準とか第二水準とか。日本語専用。記号含む。
区点コードという背番号を文字に振っている

UNICODE
世界中のすべての文字を収録することにした。何万字?
シフトJIS とか EUC は、この文字セットをエンコードできない。
UTF-8というエンコーディングがこれを扱える。
UTF-8
UNICODEが扱えて、しかもASCII文書と互換性がある。

0~127が来たら、ASCIIと同じ文字。
192~223が来たら、次のデータとあわせて一文字分。
224~239が来たら、次と次のデータをあわせて一文字分。

「あ」を表すデータは、227, 129, 130。
(たった一文字で3バイトか…)
使っている文字セットと
エンコーディングさえわかれば、
テキストファイルは必ず読める。


わからなくても、ある程度推定はできる
機種依存文字・外字
JISで決めているのは6897文字、シフトJISで表現できる
文字数は、実はこれより数百文字多い。(EUCも)

→ JISで漏れた文字とかも、うちの製品では
  サービスで混ぜてあげよう。きっと便利だよ。
例:
機種依存文字・外字(2)
→ 独自の文字を作る機能をつけてあげたら?
  どうせ枠があまってるんだから、活用活用。
例:
結果:
文書を書いたそのコンピュータ上でないと
、完全な文書が読めない

→将来にわたって読めるという保証が
  なくなるおそれ
  せっかくテキストファイルなのに。

機種依存文字や外字には注意。
テキストファイルと一般的なワープロ
ソフトで作った文書ファイルについて

一般的なワープロソフト…
  Microsoft Word?
  JUSTシステム 一太郎?
  富士通 OASIS?

共通点:テキストだけでなく、書式なども指定できる。
      図形やイラストも混在できる。
      レイアウト機能が充実している。
      ソフトごとに、様々なセールスポイント。
      頻繁なバージョンアップ。
ワープロと違って、テキストファイルだけ
を扱うソフトを、エディタという

メモ帳
秀丸エディタ
TeraPad
vi
などなど。

特徴:
文字の大きさや色を変えた文書は作れない
基本的に、どのソフトでも互いに文書をやりとりできる
ワープロで作った文書ファイルは、
テキストファイルとして見られるか?

特に意識しない限り、そのワープロソフトでしか
認識できない特殊な形式でファイルに保存する。
これを読むためのルールは一般利用者には
知らされない、または簡単には理解できないのが普通。

開発した会社が勝手にルールを変えちゃう権利もある
Wordで文書作って…
メモ帳で読み込んでみた
テキストファイル形式の
保存に対応している
謎の引継ぎ文書
謎の添付ファイル
解決法…

・ 印刷&FAX
・ 必ず同じソフトを使わせる
・ 文字だけなら、テキスト化

・ PDFに変換してしまうのも可
  (あとで編集するのは難しいが)
PDFは正確にはテキストファイルではないが、
仕様がはっきり公開されている。
これに沿ったプログラムさえ作れば、読める。
補足的なルールを持ったテキストファイル

・ ◆

・ HTML

・ CSV

・ XML

etc.
その他の話題

・ TAB記号

・ 全角スペース・全角英数字

・ 保存する媒体

・ 「みんなが読めない文書」を望む人も
  いるのでは?
etc.

Mais conteúdo relacionado

Último

Último (10)

新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 

Destaque

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

テキストファイルの話