線型リスト

2002年2月4日作成、2024年1月1日変更
三木(作成時、IAI設備FM分科会に所属)

(注)利用したIFCのバージョンは2.0。以降のバージョンでは差異がある。

◆線型リスト

線型リストとは、いくつかの要素をカンマ「,」で区切って一列に並べたものをカッコ「()」で囲ったものである。また、線型リストの要素に線型リストを含める(入れ子にする)こともできる。

◆線型リストの使用例

線型リストの使用例としては、座標、ベクトル、関数などの表現を挙げることができる。

(x,y,z)

f(a,b)

また、もっと複雑な(入れ子になっている)例としては、IFCでも利用されているSTEPのPart21形式を挙げることができる。

#10=IFCSPACE($,$,$,$,(),$,(),$,(#11,#12,#13,#14),.INTERNAL.,'R1','Office Room',50.,100.,250.,3.3,3.5,2.5,0.05);

線型リストは入れ子にできるので、CSV形式に比べると、データの表現に関する自由度が大きい。 具体例として、照明器具の特性を表現する場合の、XML形式表現、線型リスト形式表現、CSV形式表現をそれぞれ下記に示す。 線型リスト形式は、XML形式よりデータ量が少なく、CSV形式よりはわかりやすい。

/// XML形式 ///

<器具>
<名称>直付富士型/FL40W×2灯</名称>
<間隔>1.3</間隔>
<ランプ>
<光束>2800</光束>
<灯数>2</灯数>
</ランプ>
<保守率群>
<保守率 状態="良">0.80</保守率>
<保守率 状態="中">0.75</保守率>
<保守率 状態="否">0.70</保守率>
</保守率群>
<照明率群>
<照明率 天井反射率="0.75" 壁反射率="0.5" 室指数="J">34</照明率>
<照明率 天井反射率="0.75" 壁反射率="0.5" 室指数="I">41</照明率>
<照明率 天井反射率="0.75" 壁反射率="0.5" 室指数="H">45</照明率>
<照明率 天井反射率="0.75" 壁反射率="0.5" 室指数="G">50</照明率>
<照明率 天井反射率="0.75" 壁反射率="0.5" 室指数="F">54</照明率>
<照明率 天井反射率="0.75" 壁反射率="0.5" 室指数="E">59</照明率>
<照明率 天井反射率="0.75" 壁反射率="0.5" 室指数="D">66</照明率>
<照明率 天井反射率="0.75" 壁反射率="0.5" 室指数="C">67</照明率>
<照明率 天井反射率="0.75" 壁反射率="0.5" 室指数="B">71</照明率>
<照明率 天井反射率="0.75" 壁反射率="0.5" 室指数="A">74</照明率>



<照明率 天井反射率="0.30" 壁反射率="0.1" 室指数="A">61</照明率>
</照明率群>
</器具>

/// 線型リスト形式 ///

(直付富士型/FL40W×2灯,1.3,(2800,2),(0.80,0.75,0.70),((0.75,0.5,J,34),(0.75,0.5,I,41),(0.75,0.5,H,45),(0.75,0.5,G,50),(0.75,0.5,F,54),(0.75,0.5,E,59),(0.75,0.5,D,66),(0.75,0.5,C,67),(0.75,0.5,B,71),(0.75,0.5,A,74),・・・,(0.30,0.1,A,61)))

/// CSV形式 ///

直付富士型/FL40W×2灯,1.3,2800,2,0.80,0.75,0.70,0.75,0.5,J,34,0.75,0.5,I,41,0.75,0.5,H,45,0.75,0.5,G,50,0.75,0.5,F,54,0.75,0.5,E,59,0.75,0.5,D,66,0.75,0.5,C,67,0.75,0.5,B,71,0.75,0.5,A,74,・・・,0.30,0.1,A,61

◆線型リストの処理関数

VBScriptによる処理関数の例を下記に示す。

'最初の"("からそれと同じ階層の")"までの間の文字列を取り出す
Function GetFPTP(txt_old) 'From Parenthesis To Parenthesis
  Dim txt_new,num_s,num_e,num_l,num_i1,num_i2,num_i3
  num_s = 1            'start
  num_e = Len(txt_old) 'end
  num_l = 0            'layer
  num_i1 = InStr(1,txt_old,"(",1)
  If num_i1 > 0 Then
    num_s = num_i1 + 1
    num_l = num_l + 1
    Do
      num_i2 = InStr(num_i1 + 1,txt_old,")",1)
      num_i3 = InStr(num_i1 + 1,txt_old,"(",1)
      If     num_i2 = 0 Then
          Exit Do
      ElseIf num_i2 > 0 And num_i3 = 0 Then
          num_l = num_l -1
          num_i1 = num_i2
      ElseIf num_i2 > 0 And num_i3 > 0 Then
        If num_i2 < num_i3 Then
          num_l = num_l - 1
          num_i1 = num_i2
        Else
          num_l = num_l + 1
          num_i1 = num_i3
        End If
      End If
      If num_l = 0 Then
        num_e = num_i2 - 1
        Exit Do
      End If
    Loop
  End If
  txt_new = Mid(txt_old,num_s,num_e - num_s + 1)
  GetFPTP = txt_new
End Function

'線型リストの指定項を取り出す
Function GetLLD(txt_old_org,num_tmp) 'Linear List Data
  Dim txt_old,txt_new,num_s,num_e,num_o,num_i1,num_i2,num_i3
  txt_old = GetFPTP(txt_old_org)
  num_o = 1            'order
  If num_o = num_tmp Then
    num_s = 1
  End If
  num_i1 = 0
  Do
    num_i2 = InStr(num_i1 + 1,txt_old,",",1)
    num_i3 = InStr(num_i1 + 1,txt_old,"(",1)
    If     num_i2 = 0 Then
        If     num_o = num_tmp Then
          num_e = Len(txt_old)
        End If
        Exit Do
    ElseIf num_i2 > 0 And num_i3 = 0 Then
        If     num_o = num_tmp - 1 Then
          num_s = num_i2 + 1
        ElseIf num_o = num_tmp Then
          num_e = num_i2 - 1
          Exit Do
        End If
        num_o = num_o + 1
        num_i1 = num_i2
    ElseIf num_i2 > 0 And num_i3 > 0 Then
      If num_i2 < num_i3 Then
        If     num_o = num_tmp - 1 Then
          num_s = num_i2 + 1
        ElseIf num_o = num_tmp Then
          num_e = num_i2 - 1
          Exit Do
        End If
        num_o = num_o + 1
        num_i1 = num_i2
      Else
        txt_tmp = GetFPTP(Mid(txt_old,num_i3))
        num_i1 = num_i3 + Len(txt_tmp) + 1
      End If
    End If
  Loop
  txt_new = Mid(txt_old,num_s,num_e - num_s + 1)
  GetLLD = txt_new
End Function

実行結果を下記に示す。

Response.Write GetFPTP("((x(xx)xxx))")
→(x(xx)xxx)

Response.Write GetLLD("(x,(xx,x),xxx)",2)
→(xx,x)

参考資料

人工知能システムの構成、近代科学社、2001年4月


目次