type:"Data"
블록을 찾은 다음 원하는 텍스트로 바꿉니다. 다음 중 하나 이상이있을 수있는 샘플 입력이 아래와 같습니다
는 :C#에서이 정규식을 어떻게 얻을 수 있습니까?
find and select a block starting with layer,
there can be any number of space characters but after it
there should be a { character,
then there can be anything(for making it easier), and then
there should be a type followed by any number of spaces, then followed by "Data"
then anything can be there, until it is faced with a } character
:
((layer)(*)((\n))*{((.*?)(\n)*)*(type)(*):(*)("Data")((.*?)(\n)*)*)(.*?)(\n)}
나는이 모델을 시도 :
layer {
name: "cifar"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
mean_file: "examples/cifar10/mean.binaryproto"
mirror: true
#crop_size: 20
}
# this is a comment!
data_param {
source: "examples/cifar10/cifar10_train_lmdb"
batch_size: 100
backend: LMDB
}
}
layer {
name: "cifar"
type: "Data"
top: "data"
top: "label"
include {
phase: TEST
}
transform_param {
mean_file: "examples/cifar10/mean.binaryproto"
}
data_param {
source: "examples/cifar10/cifar10_test_lmdb"
batch_size: 25
backend: LMDB
}
}
나는이 정규식 함께했다
하지만 분명히 제대로 작동하지 않습니다. 나는이 레이어 블록의 어느 유형을 변경하는 경우, 아무것도 type : "Data"
@ 스티브 : 그렇지 않습니다. 키 (및 일부 값)는 따옴표로 묶이지 않고 쉼표가 없으며 주석에 '#'이 사용될 수도 있습니다. – Ryan
이 예에서'type'은'layer's에만 나타나며'name'과 항상'top' 다음에옵니다. 이것이 항상 사실이라면 정규 표현식을 상당히 단순화 할 수 있습니다. 그렇지 않은 경우이 모델은 어떤 데이터 구조입니까? 더 확실하게 데이터를 읽는 데 사용할 수있는 tokenizer/parser/AST가 있습니까? 아니면 먼저 JSON/XML로 변환 할 수 있습니까? – Orphid
일치하지 않으려는 블록을 식별하는 요소 - 블록에 계속 연결할 수있는 요소가 일관되게 포함되어 있습니까? 'type : "Foo"'그런 다음 모든 블록이'type : "Data"'를 가진 것들이 될 다른 블록들과 함께 남겨 지도록 제외 할 것인가? –