2016-09-26 11 views
1

インポートされたメタデータには、DMにインポートした後の単一の文字列である、事前定義されたネスト構造(例を示します)があります。 メタデータ全体と各ブランチレベルが中括弧{}に含まれています。すべてのキーとキー値は引用符 ""で区切られ、コロンで区切られています。ネストされた文字列(メタデータ)をTagGroupにラップする方法

質問:データを変換してラップする方法TagGroupオブジェクトに追加することで、インデックス作成、検索、データアクセス操作を簡単に行うことができます。

ありがとうございます!ここで

は一例です:

{ 
    "Acquisition": { 
     "AcquisitionStartDatetime": { 
      "DateTime": "1473763749" 
     }, 
     "AcquisitionDatetime": { 
      "DateTime": "0" 
     }, 
     "BeamType": "", 
     "SourceType": "Monochromator" 
    }, 
    "BinaryResult": { 
     "AcquisitionUnit": "", 
     "CompositionType": "", 
     "DetectorIndex": "3", 
     "Detector": "HAADF", 
     "PixelSize": { 
      "width": "5.408370946750477e-010", 
      "height": "5.408370946750477e-010" 
     }, 
     "PixelUnitX": "m", 
     "PixelUnitY": "m", 
     "Offset": { 
      "x": "-2.769085924736244e-007", 
      "y": "-2.769085924736244e-007" 
     }, 
     "Encoding": "" 
    }, 
    "Sample": "", 
    "GasInjectionSystems": "" 
} 
+0

変換され、 .emd)は、HDF5ベースのファイル形式です。私はファイルのインポートを行うための作業スクリプトを実装しようとしています。どんな助けもありがとう! – w4m

+0

これは、中程度に洗練された再帰的な文字列パーサーが必要になると思われます。このパーサーは、このフォーラムの質問に対する簡単な答えとして簡単には提供されません。私は、DMにXMLをインポートするための同様のパーサーを実行しており、アプリケーションを手助けすることに興味があります。共同作業に興味がある場合は、私のプロフィールにあるウェブサイト/連絡先から私に連絡してください。 –

+0

Veloxのインポートスクリプトを使用することは、多くの人々が興味を持っているかもしれないことです。いったん作業をしたら、[DM scripting database](http://www.felmi-zfe.at/dm-script/)に提出することができれば素晴らしいでしょう。 – BmyGuest

答えて

1

編集:固定コード今

私はより多くのクリーンアップバージョンが可能であるが、それはタスクんいくつかの確信している:実際には、このメタデータは、(FEI Velox社から1.2のデータを

Class CMetaStringToTagGroup 
{ 
    // Find next string bracketed by " in input string, starting search 
    // at given index. Returns string and end-position of search 
    string FindNextKeyName(object self, string input, number & searchPos) 
    { 
     number totalLength = len(input) 
     number start = 0, end = 0 
     while(searchPos < totalLength) 
     { 
      searchpos++ 
      if ("\"" == input.mid(searchpos-1,1)) 
      { 
       if (!start) 
        start = searchpos-1 
       else 
        { 
        end = searchpos-1 
        return input.mid(start+1,end-start-1) 
        } 
      } 
     } 
     return "" 
    } 

    // Returns the next of either "{" , "}" or """ after a collon ":" 
    string GetNextIndicator(object self, string input, number & searchPos) 
    { 
     number totalLength = len(input) 
     while(searchPos < totalLength) 
     { 
      searchpos++   
      if ("{" == input.mid(searchpos-1,1)) 
       return "{" 
      if ("}" == input.mid(searchpos-1,1)) 
       return "}" 
      if ("\"" == input.mid(searchpos-1,1)) 
       return "\"" 
     } 
     return "" 
    } 

    // In a tag-path string, find location of last colon 
    number findLastColon(object self, string input) 
    { 
     number totalLength = len(input) 
     number lastPos = -1 
     number searchPos = 0 
     while(searchPos < totalLength) 
     { 
      searchpos++ 
      if (":" == input.mid(searchpos-1,1)) 
       lastPos = searchpos-1 
     } 
     return lastPos 
    } 

    // Parse textstring and create taggroup from it 
    TagGroup CreateTagFromText(object self, string input) 
    { 
     TagGroup rootTG = NewTagGroup() 
     string currentPath = "" 

     number totalLength = len(input) 
     number searchPos = 0 
     number searchPos2 
     string keyName, indicator 
     while(searchPos < totalLength) 
     { 
      // search for new key or closing bracket, whatever first 
      searchPos2 = searchPos 
      indicator = self.GetNextIndicator(input, searchPos2) 
      keyName = self.FindNextKeyName(input, searchPos) 
      if (("}" == indicator) && (searchpos2<searchPos)) 
      { 
       // decrease hierachy 
       number cutPos = self.findLastColon(currentPath) 
       currentPath = left(currentPath, cutPos) 
       result("\n DEC ") 
       searchPos = searchPos2 
      } 
      else 
      { 
       // Either add value or new sub-tagGroup 
       if ("" == keyname) break; // No more keys found 
       indicator = self.GetNextIndicator(input, searchPos) 
       if ("" == indicator) break; // No more indicator found -- should not happen! 

       if ("{" == indicator) 
       { 
        // increase hierachy 
        currentPath += ":" + keyname 
        rootTg.TagGroupSetTagAsTagGroup(currentPath, NewTagGroup()) 
        result("\n INC ("+keyname+")") 
       } 
       else if ("\"" == indicator) 
       { 
        // Add value 
        searchPos-- 
        string valStr = self.FindNextKeyName(input, searchPos) 
        rootTg.TagGroupSetTagAsString(currentPath + ":" + keyname, valStr) 
        result("\n VAL("+keyname+") ") 
       } 
      } 
     } 
     return rootTg 
    } 
} 

{ 
    // Reading input text 
    number fileID = OpenFileForReading("C:\\test.txt") 
    object fStream = NewStreamFromFileReference(fileID,1) 
    string inputStr = fStream.StreamReadAsText(0, fStream.StreamGetSize()) 

    // Parsing text 
    number searchPos = 0 
    TagGroup con = alloc(CMetaStringToTagGroup).CreateTagFromText(inputStr) 
    con.TagGroupopenBrowserwindow("",0) 
} 

enter image description here

+0

ありがとう!結果は完全に正しいとは思われません... "Acquisition"、 "BinaryResult"、 "Sample"、 "GasInjectionSystem"は同じレベルになければなりません。メタデータの構造に関する私の見解によれば、フォルダは["FOLDER_NAME":{]というパターンを持ち、エントリは["ENTRY_NAME": "ENTRY_VALUE"]パターンを持ち、最初の{と最後の}文字をスキップする方が良い。私はあなたのコードに最初に従おうとします... – w4m

+0

@ w4mは今それを修正しました。 – BmyGuest

+0

ところで、この素敵なタググループをイメージタグに書き込む既存の関数はありますか? DMヘルプとハンドブックの文書によると、「Set ... Note(image、string)」という機能のグループしか見つかりませんでした。 – w4m

2

マイクはコメントで指摘したように、これはかなり困難な作業よりも面倒です。フォーマットを変える別のクラスの小さなパーサースクリプトを作成するのに最適。

"NAME: {タググループラベルNAMEと階層レベルの増加。 タグラベル名と値VALUEの

"NAME": "VALUE"

ステップ 'hierachyレベル低減' のに

}

タググループを作成するときは、後の時点で数値として読み上げたい場合でも、常にStringを使用できることに注意してください。

新しいタグがそのレベルで追加されるように、あなたが入っている「タググループレベル」を随時ブラウズして覚えておいてください。無効なテキストセクションをスキップします。

DigitalMicrographのF1ヘルプdocumenationはあなたが必要とする可能性が最も高いですコマンドを示します文字列のセクション、があります。また、私は文字列のtert-ブチルオペレータにユーザーにそれが時には便利

String StringAppend(String s1, String s2) 
Number StringCompare(String s1, String s2) 
Boolean StringIsValid(String str) 
String StringToLower(String str) 
String StringToUpper(String str) 
Number len(String str) 
String left(String str, Number count) 
String mid(String str, Number offset, Number count) 
String right(String str, Number count) 
Number find(String s1, String s2) 
Number val(String str) 

をlike

number isOK = 1 
string str = isOK == 1 ? "true" : "false" 

また、解析時には、タブレーターと改行文字を監視します。文字列にintを指定するときは\を制御文字と解釈するので、\ nと\ tを使用する必要があります。

関連する問題