I have an XML file that represents the syntax trees of all the sentences in a book:
<book>
<sentence>
<w class="pronoun" role="subject">
I
</w>
<wg type="verb phrase">
<w class="verb" role="verb">
like
</w>
<wg type="noun phrase" role="object">
<w class="adj">
green
</w>
<w class="noun">
eggs
</w>
</wg>
</wg>
</sentence>
<sentence>
...
</sentence>
...
</book>
Run Code Online (Sandbox Code Playgroud)
This example is fake, but the point is that the actual words (the <w> elements) are nested in unpredictable ways based on syntactic relationships.
What I'm trying to …
我的XQuery是:
declare namespace xsd="http://www.w3.org/2001/XMLSchema";
for $schema in xsd:schema
for $nodes in $schema//*,
$attr in $nodes/xsd:element/@name
where fn:contains($attr,'city')
return $attr
Run Code Online (Sandbox Code Playgroud)
返回: name="city" name="city" name="city" name="city" name="city"
当我添加区分值如:
declare namespace xsd="http://www.w3.org/2001/XMLSchema";
for $schema in xsd:schema
for $nodes in $schema//*,
$attr in $nodes/xsd:element/@name
where fn:contains($attr,'city')
return distinct-values($attr)
Run Code Online (Sandbox Code Playgroud)
返回: city city city city city
我只需要返回一个"城市",我该怎么办呢?
我试图在 QConsole 中插入以下代码,但不断收到下面提到的错误。
[1.0-ml] XDMP-ENTITYREF: (err:XPST0003) Invalid entity reference " "
Stack Trace
At line 4 column 6:
In xdmp:eval("xquery version "1.0-ml"; let $uri := "/mlrepo...", (), <options xmlns="xdmp:eval"><database>1979476059788016196</database>...</options>)
2. let $uri := "/mlreports/corb/arena_report.txt"
3. let $code :=
4. <code>
5. THREAD-COUNT=10
6. BATCH-SIZE=10
Run Code Online (Sandbox Code Playgroud)
下面是查询,我正在执行 -
xquery version "1.0-ml";
let $uri := "/mlreports/corb/arena_report.txt"
let $code :=
<code>
THREAD-COUNT=10
BATCH-SIZE=10
URIS-MODULE=/mlreports/selector/arena_report_selector.xqy
PROCESS-MODULE=/mlreports/transform/arena_report_transform.xqy
PROCESS-TASK=com.marklogic.developer.corb.ExportBatchToFileTask
EXPORT-FILE-NAME=arena_report.csv
PRE-BATCH-TASK=com.marklogic.developer.corb.PreBatchUpdateFileTask
EXPORT-FILE-TOP-CONTENT=UNIFIED DOC ID,SEAL ID,DMS NAME,DOCUMENT ID,PRODUCT ID,Legal Entity ID,Client ID,Client Type,Party Role,Document Type ID,Document Type Name,Document Title …Run Code Online (Sandbox Code Playgroud) 我正在尝试执行此查询:
declare variable $doc as xs:string external;
declare namespace type4="http:///de/tudarmstadt/ukp/dkpro/core/api/segmentation/type.ecore";
fn:doc($doc)//type4:Lemma/@value
Run Code Online (Sandbox Code Playgroud)
在BaseX java驱动程序中.实际的代码段如下所示:
String queryString = "declare variable $doc as xs:string external; " +
"declare namespace type4=\"http:///de/tudarmstadt/ukp/dkpro/core/api/segmentation/type.ecore\"; " +
"fn:doc($doc)//type4:Lemma/@value";
Set<String> lemmata = new TreeSet<>();
try (ClientQuery query = this.clientSession.query(queryString))
{
query.bind("$doc", this.getUriFromDocumentId(documentId));
while (query.more())
{
String next = query.next();
logger.info(next);
lemmata.add(next);
}
return lemmata;
} catch (IOException e)
{
e.printStackTrace();
throw new QHException(e);
}
Run Code Online (Sandbox Code Playgroud)
我得到了这个例外:
[XPST0003] Unexpected end of query: 'namespace type4...'
Run Code Online (Sandbox Code Playgroud)
在打电话时query.more().
我声明命名空间错了吗?java代码中的转义引号是否有错误?我不明白xquery从何处获取查询结束.
命名空间也在我查询的xml文档中声明.
编辑:this.getUriFromDocumentId(String documentId)只是预先设置数据库名称,以便uri完成并实际匹配我想要查询的文档.在上面的代码片段执行之前,我检查说该文档存在.