-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#4533 - BioC exported from INCEpTION cannot be imported again due to …
…missing mandatory metadata - Make sure that key, date and source are generated if they are not present in the CAS when writing BioC - Make reading BioC more robust so that it does not fail if key, date or source are missing
- Loading branch information
Showing
5 changed files
with
136 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
.../inception-io-bioc/src/test/java/de/tudarmstadt/ukp/inception/io/bioc/BioCWriterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Licensed to the Technische Universität Darmstadt under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The Technische Universität Darmstadt | ||
* licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.tudarmstadt.ukp.inception.io.bioc; | ||
|
||
import static org.apache.uima.fit.factory.AnalysisEngineFactory.createEngine; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.File; | ||
|
||
import org.apache.uima.fit.factory.CasFactory; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import de.tudarmstadt.ukp.dkpro.core.api.metadata.type.DocumentMetaData; | ||
|
||
class BioCWriterTest | ||
{ | ||
@Test | ||
void thatMetadataIsGeneratedToOutput(@TempDir File aTmp) throws Exception | ||
{ | ||
var cas = CasFactory.createCas(); | ||
cas.setDocumentText("This is a test"); | ||
|
||
var dmd = DocumentMetaData.create(cas); | ||
dmd.setCollectionId("collectionId"); | ||
dmd.setDocumentId("documentId"); | ||
|
||
var writer = createEngine( // | ||
BioCWriter.class, // | ||
BioCWriter.PARAM_TARGET_LOCATION, aTmp); | ||
|
||
writer.process(cas); | ||
|
||
var out = new File(aTmp, "documentId.xml"); | ||
assertThat(out).exists() // | ||
.content() // | ||
.contains("<source>collectionId</source>") // | ||
.contains("<date>") // | ||
.contains("<key>documentId</key>"); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
inception/inception-io-bioc/src/test/resources/bioc/example-with-incomplete-metadata.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<collection> | ||
<key/> | ||
<document> | ||
<id>1</id> | ||
<passage> | ||
<offset>0</offset> | ||
<text>Document 1 text.</text> | ||
</passage> | ||
</document> | ||
<document> | ||
<id>2</id> | ||
<passage> | ||
<offset>0</offset> | ||
<text>Document 2 text.</text> | ||
</passage> | ||
</document> | ||
<document> | ||
<id>3</id> | ||
<passage> | ||
<offset>0</offset> | ||
<text>Document 3 text.</text> | ||
</passage> | ||
</document> | ||
</collection> |