使用節點對象的attribute_paths
方法來獲取可用數據的列表。
轉到Prague Markup Language Documentation並下載所有的示例架構的(他們稱對方...)
example1.xml
example1_schema.xml
example2.xml
example2_schema.xml
...
在這個例子中,我使用example7.xml
得到的路徑列表,您可以使用獲取數據。存儲在PML節點的數據來自以下 句子:
約翰愛瑪麗。他星期五告訴她。
下面是代碼:
#!/usr/bin/env perl
use strict;
use warnings;
use Treex::PML;
my $document = Treex::PML::Factory->createDocumentFromFile('example7.xml');
foreach my $tree ($document->trees) {
my $node = $tree;
while ($node) {
$node = $node->following; # depth-first traversal
my @paths = $node->attribute_paths();
print "Can call the following:\n";
for (@paths) {
print '$node->all("' . $_ . '");' . "\n";
my ($value) = $node->all($_);
print " ==> $value\n";
}
exit 0;
}
}
輸出:
Can call the following:
$node->all("label");
==> NP
$node->all("w/id");
==> t#s1w1
$node->all("w/#content");
==> John
謝謝!現在只是看到這個,出於某種原因。 – alexis