メインコンテンツまでスキップ

チャンク表現のローカルとグローバルプロパティ

チャンク表現は、SenseTalkスクリプトでテキストデータを扱う強力な方法を提供します。ここで説明するローカルおよびグローバルプロパティを使用すると、チャンクへのアクセス方法を制御することができます。SenseTalkでチャンクを使用する方法の詳細については、チャンク表現を参照してください。

ローカルとグローバルのプロパティ値の設定または変更:

SenseTalkのコマンドSetまたはPutを使用してグローバルプロパティの値を設定することができます。これらのプロパティのいずれかを参照するときは、通常の変数と区別するためにプロパティ名の前にtheを使用する必要があります。

例:

set the searchrectangle to [1,2,2,3]
put 2 into the remoteworkinterval

以下のようにグローバルプロパティ内の特定の名前付きプロパティを追加または変更することができます:

set the namedColors.pink to color("RGB,1.0,0.5,0.5") -- namedColorsグローバルプロパティにpinkを追加し、そのRGBカラー値を定義します
set the listFormat's separator to " & " -- listFormatグローバルプロパティのseparatorプロパティを設定します

プロパティは、setoptionまたはsetoptionsコマンドを使用して設定または更新することもできます。setoptionコマンドを使用すると、単一のプロパティを更新することができます。setoptionsを使用すると、複数のプロパティを一度に更新することができます。

例:

setoption searchrectangle, [1,2,2,3]
setoptions {searchrectangle: [1,2,2,3], scriptlogging: yes}
ノート

setoptionおよびsetoptionsはグローバルおよびローカルプロパティの使用に特化しているため、これらのコマンドのコマンド構文でプロパティ名からtheを省略します。

ローカルおよびグローバルプロパティの操作に関する詳細情報についてはmd ローカルとグローバルプロパティのSenseTalkを参照してください。

the wordDelimiterローカルプロパティ、the defaultWordDelimiterグローバルプロパティ

,

値: 任意の文字または文字のリストで、コンテナ内の単語間のセパレータとして機能します

デフォルト:

  • the wordDelimiterの場合:the defaultWordDelimiterグローバルプロパティの現在の値
  • the defaultWordDelimiterの場合:スペース、タブ、リターン

動作: これらのプロパティは、コンテナ内の単語間のセパレータとして認識される文字のセットを指定します。これらの文字の任意の順序または組み合わせのシーケンスは、単語間に現れることができます。

the wordDelimiterプロパティは各ハンドラーにローカルです。ハンドラーの値を設定すると、そのハンドラーから呼び出される他のハンドラーの値には影響しません。各ハンドラーが実行を開始すると、そのハンドラーのthe wordDelimiterthe defaultWordDelimiterグローバルプロパティの値に初期設定されます。

例:

set the itemDelimiter to "|" // Changes the local item delimiter to pipe

例:

put "A man, a plan, a canal. Panama!" into palindrome
put word 4 of palindrome //Returns 'plan,'
set the wordDelimiter to ".,!?;:" & space & tab
put word 4 of palindrome //Returns 'plan'
set the wordDelimiter to ",."
put word 4 of palindrome //Returns ' Panama!'

例:

md
set the defaultWordDelimiter to " " // Changes the word delimiter to space across all handlers

例:

set LookupNumber to "102,311,421.000.631.521"
set the DefaultWordDelimiter to comma&period
set Row to the fifth word of LookupNumber
log Row // Displays '631'
ノート

単語チャンク式に直接デリミタを指定することもできます。これには、カスタムチャンクで説明されているようにdelimited by句を含めます。

関連項目:

  • the lineDelimiter
  • the itemDelimiter

the wordQuotes ローカルプロパティ、the defaultWordQuotes グローバルプロパティ

値: 開始と終了の引用符デリミタの2つの値のリスト、または開始と終了のデリミタとして使用される単一の値。また、emptyまたはNoneに設定して単語の引用を無効にするか、Standardに設定してデフォルトの引用を復元することもできます。

デフォルト:

  • the wordQuotesの場合:the defaultWordQuotesグローバルプロパティの現在の値
  • the defaultWordQuotesの場合:直接の二重引用符

動作: これらのプロパティは、単語チャンクの中で引用された「単語」を識別するために使用される引用符の文字または文字を指定します。デフォルトでは、ダブルクォート文字で始まる任意の単語は、次のダブルクォート文字(the wordDelimiterローカルプロパティからの任意の包含された文字を含む)までのすべての文字を含みます。

the wordQuotesプロパティは各ハンドラーにローカルです。ハンドラーの値を設定すると、そのハンドラーから呼び出される他のハンドラーの値には影響しません。各ハンドラーが実行を開始すると、そのハンドラーのthe wordQuotesthe defaultWordQuotesグローバルプロパティの値に初期設定されます。

例:

set the wordQuotes to "*"

例:

set Introduction to "Welcome to *The Manor*"
log the third word of Introduction // Displays '*The
set the wordQuotes to "*"
log the third word of Introduction // Displays '*The Manor*'

例:

set the wordQuotes to empty -- Disable quoting
put "Hi, I'm [[my long name]]" into format
set the wordQuotes to ("[[","]]")
put word 3 of format -- [[my long name]]
set sentence to <<Jack said "Let's go see a movie.">>
put word 3 of sentence -- "Let's go see a movie."
set the wordQuotes to empty -- Disable quoting
put word 3 of sentence -- "Let's

例:

set the DefaultWordQuotes to none // Disables word quoting

例:

set Introduction to <<Welcome to "The Manor">>
put word 3 of Introduction // Displays '"The Manor"'
set the DefaultWordQuotes to none
set Introduction to <<Welcome to "The Manor">>
put word 3 of Introduction // Displays '"The'

the lineDelimiter ローカルプロパティ、the defaultLineDelimiter グローバルプロパティ

値: ラインチャンク式を評価するときにラインアイテムを分離できる文字列のリスト。リスト内のアイテムの順序は重要で、与えられた順序で一致します。たとえば、一般的なラインエンディングCR、LF、CRLFに一致するには、CRの前にCRLFをリストにしてください。そうしないと、テキスト内でCRLFに遭遇した場合、最初にCRに一致し、2つのラインエンディングが連続しているとみなされます。the lineDelimiteremptyに設定すると、標準のラインエンディング:CRLF、Return、CarriageReturn、LineSeparator、ParagraphSeparatorに戻ります。

デフォルト:

  • the lineDelimiterに対して:the defaultLineDelimiterグローバルプロパティの現在の値
  • the defaultLineDelimiterに対して:標準的な行終端のリスト:CRLF、Return、CarriageReturn、LineSeparator、ParagraphSeparator

**動作:**これらのプロパティは、テキストの行間を区切るデリミタ文字列のリストを指定します。Return文字(技術的にはこの文字は行フィード、LF)などの特定の行終端タイプに行デリミタを変更することができます。この設定は、スクリプトが対話するほとんどのテキストでうまく動作します。異なるプラットフォーム(Mac、Windows、Linux)で生成されたテキストファイルは、他の行終端を使用するかもしれません。

さまざまなファイルを簡単に操作できるように、the lineDelimiterは初めてCRLF、Return、CarriageReturn、LineSeparator、ParagraphSeparatorという標準的な行終端のリストに設定されます。the lineDelimiterをカスタムリストに設定した場合、後で空に設定すると、自動的に標準リストに復元するショートカットとして利用できます。

いくつかの異なる文字によって分割されたテキストのチャンクにアクセスするために、the lineDelimiterを変更したいかもしれません。これは、デリミタのリストを提供するという事実を利用するためです。

the lineDelimiterプロパティは、各ハンドラーにローカルです。一つのハンドラーでその値を設定しても、そのハンドラーから呼び出される他のハンドラーの値には影響しません、また逆も同様です。各ハンドラーが実行を開始すると、そのハンドラーのthe lineDelimiterは最初にthe defaultLineDelimiterグローバルプロパティの値に設定されます。

例:

set the LineDelimiter to ","

例:

set stuff to "button" & tab & "paperclip" & tab & "pencil"
set the lineDelimiter to tab
log the second line of stuff // Displays 'paperclip'

例:

set the lineDelimiter to empty -- Use all standard line endings
put "C:\songs/Solas/BlackAnnis" into songPath
set the lineDelimiter to ("/","\")
put line 2 of songPath -- "songs"

例:

set the DefaultLineDelimiter to tab

例:

set stuff to "button" & tab & "paperclip" & tab & "pencil"
set the DefaultLineDelimiter to tab
repeat with each line of stuff
put it
end repeat

上記のコマンドの出力は、以下のようになるでしょう:

button
paperclip
pencil
ノート

delimited by句を含むことで直接行チャンク表現にデリミタのリストを指定することもできます。詳細はカスタムチャンクをご覧ください。

関連項目:

  • the wordDelimter
  • the itemDelimiter

the itemDelimiterローカルプロパティ、the defaultItemDelimiterグローバルプロパティ

値: 通常、一つの文字

デフォルト:

  • the itemDelimiterに対して:the defaultItemDelimiterグローバルプロパティの現在の値
  • the defaultItemDelimiterに対して:, (カンマ)

動作: これらのプロパティは、コンテナ内のテキストアイテム間の区切りとして認識される文字を指定します。最もよく、デリミタとして一つの文字が使用されますが、必要に応じてより長い文字列に設定することもできます。

the itemDelimiterプロパティは、各ハンドラにローカルです。一つのハンドラでその値を設定しても、そのハンドラから呼ばれた他のハンドラの値には影響しませんし、逆もまた然りです。各ハンドラが実行を開始すると、そのハンドラ内のthe itemDelimiterは、初期設定としてthe defaultItemDelimiterグローバルプロパティの値に設定されます。

例:

set the itemDelimiter to "*"

例:

put "A man, a plan, a canal. Panama!" into palindrome
set the itemDelimiter to "."
put item 2 of palindrome //Displays" Panama!"

例:

// 以下の関数は、フルファイルパスを入力として受け取り、ファイルのディレクトリのみを返します。これは、"/"をアイテムデリミタとしてパスを解析することによって行います。
function pathOfFile filename
set the itemDelimiter to "/"
delete the last item of filename
return filename
end pathOfFile

例:

set the DefaultItemDelimiter to "/"

例:

set the DefaultItemDelimiter to period
log item 2 of "apple.pie" // Displays 'pie'
ノート

Custom Chunksで説明されているように、アイテムチャンク表現で直接デリミタを指定することもできます。

関連:

  • the wordDelimter
  • the lineDelimiter

the characterFillerグローバルプロパティ

デフォルト: . (ピリオド)

値: 通常は標準的な行区切れ文字(技術的には、任意の単一の文字または文字列を使用することができます)

振る舞い: このプロパティは、コンテナがその内容の終端を越えるキャラクターチャンクに格納することで拡張されたときの振る舞いを指定します。

the characterFillerは、必要に応じて繰り返し使用され、コンテナを所望の長さまで満たします。必要に応じて単一の文字またはより長い文字列に設定できます。

例:

set the characterFiller to "|"

例:

put "zig" into test
set the characterFiller to "/\"
put "zag" into character 9 of test
put test -- "zig/\/\/zag"

the lineFillerグローバルプロパティ

デフォルト: Return

値: 単一の文字または文字列

振る舞い: このプロパティは、コンテナがその内容の終端を越えるチャンクの行に格納することで拡張されたときの振る舞いを指定します。

the lineFillerプロパティは、コンテナを要求された行数まで満たすときに使用する行デリミタを提供します。通常、これはthe defaultLineDelimiterプロパティにリストされている値の一つに設定するべきです。行デリミタでない文字または文字列を使用すると、その値は必要な回数だけ挿入され、正しい行を提供するかのように振る舞いますが、実際には、この振る舞いはthe characterFillerプロパティと同様に操作し、新しい行を作成しません。

例:

set the lineFiller to CRLF

例:

set the lineFiller to "blank line" & return
put "bob" into line 3 of lineVar
put lineVar

例:

the wordFillerグローバルプロパティ

値: 単一の文字または文字列、または2つの値のリスト(2つ目の値が単語の区切りとして機能します)

デフォルト: ? (クエスチョンマーク)

振る舞い: このプロパティは、コンテナがその内容の終端を超える単語のチャンクに格納することで拡張されるときの振る舞いを指定します。

the wordFillerは、単一の値または2つの値のリストに設定できます。単一の値に設定されている場合、それは格納されている単語の数に達するために必要に応じて繰り返される埋め込み単語です。この場合、挿入された単語はthe wordDelimiterプロパティの最初の文字で区切られます(デフォルトでは、この値はスペース文字です)。the wordFillerが2つの値のリストに設定されている場合、最初の値が埋め込み単語で、2つ目の値が挿入された単語の間の区切り文字として使用されます。

例:

set the wordFiller to period

例:

set the wordFiller to period
put "10" into countdown
set word 8 of countdown to "9"
log countdown // Displays '10 . . . . . . 9'

例:

set the wordFiller to "umm..."
put "Hello and" into greeting
set word 5 of greeting to "welcome!"
put greeting -- "Hello and umm... umm... welcome!"