forked from dkpro/dkpro-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dkpro#1386 - Add further JCas annotations
- use of an "extractor" to split the file into individual documents - further JCas annotations for every document besides documentText
- Loading branch information
Showing
5 changed files
with
175 additions
and
118 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
85 changes: 0 additions & 85 deletions
85
...ord-asl/src/main/java/org/dkpro/core/io/gigaword/internal/AnnotatedGigawordDocuments.java
This file was deleted.
Oops, something went wrong.
96 changes: 96 additions & 0 deletions
96
...ord-asl/src/main/java/org/dkpro/core/io/gigaword/internal/AnnotatedGigawordExtractor.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,96 @@ | ||
/* | ||
* 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 org.dkpro.core.io.gigaword.internal; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.dkpro.core.api.io.ResourceCollectionReaderBase.Resource; | ||
/** | ||
* Read text from the Annotated Gigaword Corpus. This reader does <b>not</b> read any of the | ||
* annotations yet. | ||
*/ | ||
public class AnnotatedGigawordExtractor | ||
{ | ||
private List<AnnotatedGigawordArticle> articleList = new ArrayList<>(); | ||
|
||
public AnnotatedGigawordExtractor(Resource aResource) throws IOException | ||
{ | ||
try (InputStream fileInputStream = aResource.getInputStream(); | ||
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream); | ||
BufferedReader br = new BufferedReader(inputStreamReader)) { | ||
|
||
String sCurrentLine; | ||
|
||
Pattern GIGAWORD_DOC_ELEMENT_PATTERN = Pattern.compile("<DOC id=\"(.*?)\".*>"); | ||
String currentDocId = ""; | ||
StringBuilder currentDocText = new StringBuilder(); | ||
|
||
boolean inSentences = false; | ||
|
||
// read file | ||
while ((sCurrentLine = br.readLine()) != null) { | ||
|
||
if (sCurrentLine.contains("<DOC id=")) { | ||
currentDocText.append(sCurrentLine + "\n"); | ||
// extract new document ID | ||
Matcher m = GIGAWORD_DOC_ELEMENT_PATTERN.matcher(sCurrentLine); | ||
if (m.find()) { | ||
currentDocId = m.group(1); | ||
} else { | ||
throw new RuntimeException("Missing document ID on article"); | ||
} | ||
} | ||
else if (sCurrentLine.contains("</DOC>")) { | ||
currentDocText.append(sCurrentLine + "\n"); | ||
// save previous document | ||
if (!currentDocText.toString().equals("")) { | ||
articleList.add(new AnnotatedGigawordArticle(aResource, currentDocId, | ||
currentDocText.toString())); | ||
currentDocText = new StringBuilder(); | ||
} | ||
} | ||
|
||
if (sCurrentLine.contains("<sentences>")) | ||
{ | ||
inSentences = true; | ||
} | ||
|
||
// only save <sentences> information to reduce memory usage | ||
if (inSentences) { | ||
currentDocText.append(sCurrentLine + "\n"); | ||
} | ||
|
||
if (sCurrentLine.contains("</sentences>")) | ||
{ | ||
inSentences = false; | ||
} | ||
} | ||
} | ||
} | ||
|
||
public List<AnnotatedGigawordArticle> getArticleList() { | ||
return articleList; | ||
} | ||
} |
Oops, something went wrong.