repo stringlengths 1 191 ⌀ | file stringlengths 23 351 | code stringlengths 0 5.32M | file_length int64 0 5.32M | avg_line_length float64 0 2.9k | max_line_length int64 0 288k | extension_type stringclasses 1 value |
|---|---|---|---|---|---|---|
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/DescriptionEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import com.google.common.collect.Sets;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.*;
/**
* @author Krzysztof Rusek
*/
public class DescriptionEnhancer extends AbstractSimpleEnhancer {
private static final Pattern PREFIX = Pattern.compile("^Abstract[-:\\.]?", Pattern.CASE_INSENSITIVE);
public DescriptionEnhancer() {
setSearchedZoneLabels(EnumSet.of(BxZoneLabel.MET_ABSTRACT));
setSearchedFirstPageOnly(true);
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.DESCRIPTION);
}
@Override
protected boolean enhanceMetadata(BxDocument document, DocumentMetadata metadata) {
List<BxLine> lines = new ArrayList<BxLine>();
for (BxPage page : filterPages(document)) {
for (BxZone zone : filterZones(page)) {
for (BxLine line : zone) {
lines.add(line);
}
}
}
StringBuilder sb = new StringBuilder();
BxLine prev = null;
for (BxLine line : lines) {
String normalized = line.toText().toLowerCase(Locale.ENGLISH).trim();
if (normalized.startsWith("abstract")
|| normalized.startsWith("a b s t r a c t")
|| normalized.startsWith("article info")) {
sb = new StringBuilder();
}
if (normalized.startsWith("keywords")
|| normalized.startsWith("key words")
|| normalized.equals("introduction")
|| normalized.startsWith("this work is licensed")
|| (normalized.length() < 20 &&
(normalized.startsWith("introduction") || normalized.endsWith("introduction")))) {
break;
}
if (prev != null && !prev.getParent().equals(line.getParent()) &&
lines.indexOf(line) > 5 && prev.toText().endsWith(".") &&
(Math.abs(prev.getX()-line.getX()) > 5 || Sets.intersection(prev.getFontNames(), line.getFontNames()).isEmpty())) {
break;
}
sb.append("\n");
sb.append(line.toText().trim());
prev = line;
}
String text = sb.toString().trim();
if (!text.isEmpty()) {
Matcher matcher = PREFIX.matcher(text);
if (matcher.find()) {
text = text.substring(matcher.end()).trim();
}
metadata.setAbstrakt(text);
return true;
}
return false;
}
}
| 3,612 | 35.13 | 131 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/UrnEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.EnumSet;
import java.util.Set;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.metadata.model.IDType;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* @author Krzysztof Rusek
*/
public class UrnEnhancer extends AbstractPatternEnhancer {
private static final Pattern PATTERN = Pattern.compile("\\bURN:?\\s*(\\S+)",
Pattern.CASE_INSENSITIVE);
public UrnEnhancer() {
super(PATTERN, EnumSet.of(BxZoneLabel.MET_BIB_INFO));
}
@Override
protected boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata) {
// FIXME: Scheme for urn?
metadata.addId(IDType.URN, result.group(1));
return true;
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.URN);
}
}
| 1,727 | 31.603774 | 86 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/PublisherEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.EnumSet;
import java.util.Set;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* @author Krzysztof Rusek
*/
public class PublisherEnhancer extends AbstractPatternEnhancer {
private static final Pattern PATTERN = Pattern.compile(
"\\bpublisher[\\s:-]\\s*(.+)",
Pattern.CASE_INSENSITIVE);
private static final Set<BxZoneLabel> SEARCHED_ZONE_LABELS = EnumSet.of(BxZoneLabel.MET_BIB_INFO);
public PublisherEnhancer() {
super(PATTERN, SEARCHED_ZONE_LABELS);
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.PUBLISHER);
}
@Override
protected boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata) {
metadata.setPublisher(result.group(1));
return true;
}
}
| 1,766 | 32.339623 | 102 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/AffiliationGeometricEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import com.google.common.collect.Sets;
import java.util.*;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentAuthor;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.*;
/**
* @author Krzysztof Rusek
*/
public class AffiliationGeometricEnhancer extends AbstractSimpleEnhancer {
private static final Pattern SKIPPED_LINE_PATTERN = Pattern.compile(
".*(Email|Correspondence|Contributed equally|Dated|This work|Electronic address|The authors|Index|Received|Draft):?.*",
Pattern.CASE_INSENSITIVE);
private static final Pattern EMAIL_SIMPLE_LINE_PATTERN = Pattern.compile(
"\\S+@[^,\\s]+",
Pattern.CASE_INSENSITIVE);
private static final Pattern EMAIL_LINE_PATTERN = Pattern.compile(
"[\\{\\[]([^,\\s]+, ?)+[^,\\s]+ ?[\\}\\]]?@\\S+",
Pattern.CASE_INSENSITIVE);
private static final Pattern FULL_INDEX_PATTERN = Pattern.compile("\\d{1,2}|\\*|∗|⁎|†|‡|§|\\(..?\\)|\\{|¶|\\[..?\\]|\\+|\\||⊥|\\^|#|α|β|λ|ξ|ψ|[a-f]|¹|²|³");
private static final Pattern SIMPLE_INDEX_PATTERN = Pattern.compile("\\*|∗|⁎|†|‡|§|\\{|¶|\\+|\\||⊥|\\^|#|α|β|λ|ξ|ψ|¹|²|³");
private final Set<String> headers = Sets.newHashSet("authoraffiliations", "authordetails", "affiliations");
public AffiliationGeometricEnhancer() {
setSearchedZoneLabels(BxZoneLabel.MET_AFFILIATION);
}
public void setHeaders(Collection<String> headers) {
this.headers.clear();
for (String header : headers) {
this.headers.add(header.toLowerCase(Locale.ENGLISH));
}
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.AFFILIATION);
}
@Override
protected boolean enhanceMetadata(BxDocument document, DocumentMetadata metadata) {
Set<String> indexes = new HashSet<String>();
for (DocumentAuthor author : metadata.getAuthors()) {
indexes.addAll(author.getAffiliationRefs());
}
boolean enhanced = false;
for (BxPage page : filterPages(document)) {
Processor processor = new Processor();
for (BxZone zone : filterZones(page)) {
if (zone.getY() > page.getHeight() / 2 && zone.hasPrev() && zone.getPrev().toText().equals("Keywords")) {
continue;
}
boolean firstLine = true;
for (BxLine line : zone) {
if (firstLine) {
firstLine = false;
if (headers.contains(line.toText().toLowerCase(Locale.ENGLISH).replaceAll("[^0-9a-zA-Z]", ""))) {
continue;
}
}
if (SKIPPED_LINE_PATTERN.matcher(line.toText()).matches()
|| EMAIL_SIMPLE_LINE_PATTERN.matcher(line.toText()).matches()
|| EMAIL_LINE_PATTERN.matcher(line.toText()).matches()) {
continue;
}
double meanY = 0;
double meanH = 0;
int total = 0;
for (BxWord w : line) {
for (BxChunk ch : w) {
meanY += ch.getY();
meanH += ch.getHeight();
total++;
}
}
meanY /= total;
meanH /= total;
for (BxWord word : line) {
Iterator<BxChunk> iterator = word.iterator();
while (iterator.hasNext()) {
BxChunk chunk = iterator.next();
double chunkY = chunk.getY();
double chunkH = chunk.getHeight();
if (SIMPLE_INDEX_PATTERN.matcher(chunk.toText()).matches() ||
Math.abs(chunkY-meanY)+ Math.abs(meanH-chunkH) > 2 ||
(indexes.contains(chunk.toText()) && chunk.getParent().childrenCount() < 3
&& chunk.getParent().equals(chunk.getParent().getParent().getFirstChild()))) {
processor.addAffIndex(chunk.toText());
} else {
processor.addText(chunk.toText());
}
}
processor.endWord();
}
}
processor.endZone();
}
Map<String, String> affiliations = processor.fetchAffiliations();
if (!affiliations.isEmpty()) {
for(Map.Entry<String, String> entry : affiliations.entrySet()) {
String text = entry.getValue();
text = text.trim()
.replaceFirst("[Cc]orresponding [Aa]uthor.*$", "").trim()
.replaceFirst("[Cc]opyright is held by.*$", "").trim()
.replaceFirst("Full list of author information.*$", "").trim()
.replaceFirst("\\(?(January|February|March|April|May|June|July|August|September|October|November|December) .*$", "").trim()
.replaceFirst(" and$", "").trim()
.replaceFirst("\\S+@.*$", "").trim()
.replaceFirst("\\(?[Ee]mails?:.*$", "").trim()
.replaceFirst("\\(?[Ee]- *[Mm]ails?:.*$", "").trim()
.replaceFirst("http://.*$", "").trim()
.replaceFirst("www\\..*$", "").trim()
.replaceFirst("Acknowledgements.*$", "").trim()
.replaceFirst("[\\.,;]$", "").trim()
.replaceFirst("^[-\\)]", "").trim()
.replaceAll("(?<=[a-z])- (?=[a-z])", "");
if (text.isEmpty() || !text.matches(".*[A-Z].*") || !text.matches(".*[a-z].*")
|| text.length() < 12 || text.length() > 500) {
continue;
}
String index = entry.getKey();
if (index.startsWith("aff-")) {
index = "";
}
if (index.isEmpty()) {
if (text.matches("^[1-9]\\. .*") && indexes.contains(text.substring(0, 1))) {
while (!text.isEmpty()) {
index = text.substring(0, 1);
text = text.replaceFirst("^[1-9]\\. *", "").trim();
String t = text.replaceFirst(" *[1-9]\\. .*$", "");
String rest = text.substring(t.length()).trim();
if (!rest.isEmpty() && indexes.contains(rest.substring(0, 1))) {
if (t.length() > 20) {
metadata.setAffiliationByIndex(index, t);
}
text = rest;
} else {
if (text.length() > 20) {
metadata.setAffiliationByIndex(index, text);
}
text = "";
}
}
} else {
metadata.addAffiliationToAllAuthors(text);
}
} else {
metadata.setAffiliationByIndex(index, text);
}
enhanced = true;
}
}
}
return enhanced;
}
private static class Processor {
private static final Pattern NONAFFILIATION_PATTERN = Pattern.compile(
"Correspondence:.+|Contributed equally",
Pattern.CASE_INSENSITIVE);
private final Map<String, String> affiliations = new HashMap<String, String>();
private String affiliationRef = "";
private final StringBuilder affiliationBuilder = new StringBuilder();
private int emptyIndex = 100;
private void endAffiliation() {
if (affiliationBuilder.length() > 0) {
String text = affiliationBuilder.toString();
if (!NONAFFILIATION_PATTERN.matcher(text).matches()
&& (isIndex(affiliationRef) || affiliationRef.isEmpty())) {
if (affiliationRef.isEmpty()) {
affiliationRef = "aff-"+emptyIndex;
emptyIndex++;
}
affiliations.put(affiliationRef, text);
}
affiliationBuilder.setLength(0);
affiliationRef = "";
}
}
private boolean isIndex(String text) {
return FULL_INDEX_PATTERN.matcher(text).matches();
}
public void endWord() {
affiliationBuilder.append(" ");
}
public void endZone() {
endAffiliation();
}
public void addText(String text) {
affiliationBuilder.append(text);
}
public Map<String, String> fetchAffiliations() {
endAffiliation();
return affiliations;
}
private void addAffIndex(String toText) {
endAffiliation();
affiliationRef += toText;
}
}
}
| 10,653 | 43.391667 | 160 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/IssueEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.EnumSet;
import java.util.Set;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* @author Krzysztof Rusek
*/
public class IssueEnhancer extends AbstractPatternEnhancer {
private static final Pattern PATTERN = Pattern.compile("\\b(issue|num|no|number|n)\\.?[\\s:-]\\s*(\\d+)",
Pattern.CASE_INSENSITIVE);
private static final Set<BxZoneLabel> SEARCHED_ZONE_LABELS = EnumSet.of(BxZoneLabel.MET_BIB_INFO);
public IssueEnhancer() {
super(PATTERN, SEARCHED_ZONE_LABELS);
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.ISSUE);
}
@Override
protected boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata) {
metadata.setIssue(result.group(2));
return true;
}
}
| 1,757 | 32.807692 | 109 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/TitleEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import com.google.common.collect.Sets;
import java.util.*;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* Merged title enhancer.
*
* @author Krzysztof Rusek
*/
public class TitleEnhancer extends AbstractSimpleEnhancer {
public TitleEnhancer() {
setSearchedZoneLabels(BxZoneLabel.MET_TITLE);
setSearchedFirstPageOnly(true);
}
private final Set<String> types = Sets.newHashSet(
"case report",
"case study",
"clinical study",
"debate",
"editorial",
"forum",
"full research paper",
"methodology",
"original article",
"original research",
"primary research",
"research",
"research article",
"research paper",
"review",
"review article",
"short article",
"short paper",
"study",
"study protocol",
"technical note"
);
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.TITLE);
}
@Override
protected boolean enhanceMetadata(BxPage page, DocumentMetadata metadata) {
List<BxZone> titleZones = new ArrayList<BxZone>();
for (BxZone zone : filterZones(page)) {
if (types.contains(zone.toText().toLowerCase(Locale.ENGLISH).trim())) {
continue;
}
if (zone.toText().toLowerCase(Locale.ENGLISH).startsWith("sponsored document from")
|| (zone.hasPrev() && zone.getPrev().childrenCount() == 1 && zone.getPrev().toText().toLowerCase(Locale.ENGLISH).startsWith("sponsored document from"))) {
continue;
}
if (zone.hasNext() && zone.getNext().toText().toLowerCase(Locale.ENGLISH).replaceAll("[^a-z]", "").startsWith("journalhomepage")) {
continue;
}
titleZones.add(zone);
}
Collections.sort(titleZones, new Comparator<BxZone>() {
@Override
public int compare(BxZone t1, BxZone t2) {
return Double.compare(t2.getChild(0).getHeight(),
t1.getChild(0).getHeight());
}
});
if (!titleZones.isEmpty()) {
BxZone titleZone = titleZones.get(0);
double height = titleZone.getChild(0).getHeight();
while (titleZone.hasPrev()
&& BxZoneLabel.MET_TITLE.equals(titleZone.getPrev().getLabel())
&& Math.abs(height-titleZone.getPrev().getChild(0).getHeight()) < 0.5) {
titleZone = titleZone.getPrev();
}
StringBuilder titleSB = new StringBuilder(titleZone.toText());
while (titleZone.hasNext() && Math.abs(height-titleZone.getNext().getChild(0).getHeight()) < 0.5) {
if (BxZoneLabel.MET_TITLE.equals(titleZone.getNext().getLabel())) {
titleZone = titleZone.getNext();
titleSB.append(" ");
titleSB.append(titleZone.toText());
} else if (titleZone.getNext().childrenCount() == 1
&& titleZone.getNext().getFontNames().equals(titleZone.getFontNames())) {
titleZone = titleZone.getNext();
titleSB.append(" ");
titleSB.append(titleZone.toText());
} else {
break;
}
}
if (!titleSB.toString().isEmpty()) {
metadata.setTitle(titleSB.toString().trim().replaceAll("\n", " "));
return true;
}
}
return false;
}
}
| 4,750 | 36.117188 | 174 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/AbstractDateEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.EnumSet;
import java.util.Set;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* @author Krzysztof Rusek
*/
public abstract class AbstractDateEnhancer extends AbstractSimpleEnhancer {
private static final String[] MONTHS = {
"january|jan\\.",
"february|feb\\.",
"march|mar\\.",
"april|apr\\.",
"may",
"june|jun\\.",
"july|jul\\.",
"august|aug\\.",
"september|sep\\.",
"october|oct\\.",
"november|nov\\.",
"december|dec\\."};
private final EnhancedField field;
private Pattern simplePattern;
private Pattern anotherPattern;
public AbstractDateEnhancer(EnhancedField field, String nameRegex) {
createPatterns(nameRegex);
setSearchedZoneLabels(BxZoneLabel.MET_DATES);
this.field = field;
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(field);
}
@Override
protected boolean enhanceMetadata(BxZone zone, DocumentMetadata metadata) {
Matcher simpleMatcher = simplePattern.matcher(zone.toText());
if (simpleMatcher.find()) {
MatchResult result = simpleMatcher.toMatchResult();
String day = result.group(2);
String month = null;
for (int i = 0; i < 12; i++) {
if (result.group(i + 3) != null) {
month = String.valueOf(i + 1);
break;
}
}
String year = result.group(15);
enhanceMetadata(metadata, day, month, year);
return true;
}
Matcher anotherMatcher = anotherPattern.matcher(zone.toText());
if (anotherMatcher.find()) {
MatchResult result = anotherMatcher.toMatchResult();
String day = result.group(14);
String month = null;
for (int i = 0; i < 12; i++) {
if (result.group(i + 2) != null) {
month = String.valueOf(i + 1);
break;
}
}
String year = result.group(15);
enhanceMetadata(metadata, day, month, year);
return true;
}
return false;
}
protected abstract void enhanceMetadata(DocumentMetadata metadata, String day, String month, String year);
private void createPatterns(String nameRegex) {
StringBuilder simpleRegex = new StringBuilder();
simpleRegex.append("\\b");
simpleRegex.append(nameRegex);
simpleRegex.append("[\\s:-]\\s*((\\d{1,2})\\s+(?:");
StringBuilder anotherRegex = new StringBuilder();
anotherRegex.append("\\b");
anotherRegex.append(nameRegex);
anotherRegex.append("[\\s:-]\\s*((?:");
boolean first = true;
for (String monthRegex : MONTHS) {
if (first) {
first = false;
} else {
simpleRegex.append("|");
anotherRegex.append("|");
}
simpleRegex.append("(");
simpleRegex.append(monthRegex);
simpleRegex.append(")");
anotherRegex.append("(");
anotherRegex.append(monthRegex);
anotherRegex.append(")");
}
simpleRegex.append(")\\s+(\\d{4}))");
anotherRegex.append(")\\s+(\\d{1,2})\\s*,?\\s+(\\d{4}))");
simplePattern = Pattern.compile(simpleRegex.toString(), Pattern.CASE_INSENSITIVE);
anotherPattern = Pattern.compile(anotherRegex.toString(), Pattern.CASE_INSENSITIVE);
}
}
| 4,654 | 33.481481 | 110 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/AuthorEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import com.google.common.base.CharMatcher;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.*;
/**
* Author enhancer.
*
* This enhancer should be invoked after affiliation enhancer.
*
* @author Krzysztof Rusek
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class AuthorEnhancer extends AbstractSimpleEnhancer {
public AuthorEnhancer() {
setSearchedZoneLabels(EnumSet.of(BxZoneLabel.MET_AUTHOR));
}
@Override
protected boolean enhanceMetadata(BxDocument document, DocumentMetadata metadata) {
boolean enhanced = false;
for (BxPage page : filterPages(document)) {
for (BxZone zone : filterZones(page)) {
List<BxChunk> chunks = new ArrayList<BxChunk>();
for (BxLine l : zone) {
for (BxWord w : l) {
for (BxChunk ch : w) {
chunks.add(ch);
}
chunks.add(new BxChunk(null, " "));
}
}
chunks.remove(chunks.size()-1);
Pattern white = Pattern.compile("(\\s+)(.*)");
Pattern simpleRef = Pattern.compile("(\\d+|\\*|∗|⁎|†|‡|§|\\(..?\\)|\\{|¶|\\[..?\\]|\\+|\\||⊥|\\^|¹|²|³|#|α|β|λ|ξ|ψ)(.*)");
Pattern title = Pattern.compile("(MD|Prof.|PhD|Phd|MPH|RD|LD|BCh|BAO|PharmD|BSc|FRCP|PA-C|RAC|MBA|DrPH|MBChB|BM|RGN|BA|FCCP)([^a-zA-Z].*)");
Pattern titleEnd = Pattern.compile("(MD|Prof.|PhD|Phd|MPH|RD|LD|BCh|BAO|PharmD|BSc|FRCP|PA-C|RAC|MBA|DrPH|MBChB|BM|RGN|BA|FCCP)");
Pattern separator = Pattern.compile("(,|;|&|•|·|Æ)(.*)");
Pattern andSeparator = Pattern.compile("(and|AND)\\b(.*)");
Pattern andEndSeparator = Pattern.compile("(and|AND)");
boolean afterSep = true;
int index = 0;
String text = zone.toText().replaceAll("\n", " ");
String author = "";
List<String> refs = new ArrayList<String>();
boolean auth = false;
if (text.toLowerCase(Locale.ENGLISH).contains("vol") && text.toLowerCase(Locale.ENGLISH).contains("no")) {
continue;
}
while (!text.isEmpty()) {
Matcher whiteMatcher = white.matcher(text);
Matcher simpleRefMatcher = simpleRef.matcher(text);
Matcher titleMatcher = title.matcher(text);
Matcher titleEndMatcher = titleEnd.matcher(text);
Matcher separatorMatcher = separator.matcher(text);
Matcher andSeparatorMatcher = andSeparator.matcher(text);
Matcher andEndSeparatorMatcher = andEndSeparator.matcher(text);
if (whiteMatcher.matches()) {
index += whiteMatcher.group(1).length();
text = whiteMatcher.group(2);
afterSep = true;
author += whiteMatcher.group(1);
} else if (separatorMatcher.matches()) {
index += separatorMatcher.group(1).length();
text = separatorMatcher.group(2);
afterSep = true;
auth = false;
} else if (afterSep && andSeparatorMatcher.matches()) {
index += andSeparatorMatcher.group(1).length();
text = andSeparatorMatcher.group(2);
afterSep = true;
auth = false;
} else if (afterSep && andEndSeparatorMatcher.matches()) {
text = "";
} else if (afterSep && titleMatcher.matches()) {
index += titleMatcher.group(1).length();
text = titleMatcher.group(2);
afterSep = true;
} else if (afterSep && titleEndMatcher.matches()) {
text = "";
} else if (simpleRefMatcher.matches()) {
index += simpleRefMatcher.group(1).length();
text = simpleRefMatcher.group(2);
afterSep = true;
refs.add(simpleRefMatcher.group(1));
auth = false;
} else {
BxChunk chunk = chunks.get(index);
double chunkY = 0;
double chunkH = 0;
double meanY = 0;
double meanH = 0;
if (chunk.getBounds() != null) {
chunkY = chunk.getY();
chunkH = chunk.getHeight();
BxLine line = chunk.getParent().getParent();
int total = 0;
for (BxWord w : line) {
for (BxChunk ch : w) {
meanY += ch.getY();
meanH += ch.getHeight();
total++;
}
}
meanY /= total;
meanH /= total;
}
if (chunk.toText().matches("[a-f]") && Math.abs(chunkY-meanY)+ Math.abs(meanH-chunkH) > 2) {
index += 1;
afterSep = true;
refs.add(text.substring(0, 1));
text = text.substring(1);
auth = false;
} else {
if (!auth && !author.trim().isEmpty()) {
author = CharMatcher.WHITESPACE.trimFrom(author);
if (!author.equalsIgnoreCase("article info") && author.matches(".*[a-zA-Z].*")
&& author.length() > 4 && author.length() < 50) {
metadata.addAuthor(author, refs);
}
author = "";
refs.clear();
}
auth = true;
author += text.substring(0, 1);
index++;
text = text.substring(1);
afterSep = false;
}
}
}
if (!author.isEmpty() && !author.toLowerCase(Locale.ENGLISH).endsWith("introduction")) {
author = CharMatcher.WHITESPACE.trimFrom(author);
if (!author.equalsIgnoreCase("article info") && author.matches(".*[a-zA-Z].*")
&& author.length() > 4 && author.length() < 50) {
metadata.addAuthor(author, refs);
}
}
enhanced = true;
}
if (enhanced) {
return true;
}
}
return false;
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.AUTHORS);
}
}
| 8,440 | 44.38172 | 156 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/AuthorTitleSplitterEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import pl.edu.icm.cermine.exception.AnalysisException;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.HierarchicalReadingOrderResolver;
import pl.edu.icm.cermine.structure.ReadingOrderResolver;
import pl.edu.icm.cermine.structure.model.BxDocument;
import pl.edu.icm.cermine.structure.model.BxLine;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
import pl.edu.icm.cermine.structure.tools.BxBoundsBuilder;
/**
* Author enhancer.
*
* This enhancer should be invoked after affiliation enhancer.
*
* @author Krzysztof Rusek
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class AuthorTitleSplitterEnhancer extends AbstractSimpleEnhancer {
public AuthorTitleSplitterEnhancer() {
setSearchedZoneLabels(EnumSet.of(BxZoneLabel.MET_AUTHOR));
}
@Override
protected boolean enhanceMetadata(BxDocument document, DocumentMetadata metadata) {
for (BxZone zone : document.getFirstChild()) {
if (BxZoneLabel.MET_TITLE.equals(zone.getLabel())) {
return false;
}
}
ReadingOrderResolver roResolver = new HierarchicalReadingOrderResolver();
BxZone toDel = null;
BxZone toAdd1 = null;
BxZone toAdd2 = null;
for (BxZone zone : filterZones(document.getFirstChild())) {
BxZone z1 = new BxZone();
z1.setLabel(BxZoneLabel.MET_TITLE);
BxBoundsBuilder b1 = new BxBoundsBuilder();
BxZone z2 = new BxZone();
z2.setLabel(BxZoneLabel.MET_AUTHOR);
BxBoundsBuilder b2 = new BxBoundsBuilder();
boolean wasAuthor = false;
BxLine prev = null;
for (BxLine line : zone) {
if (prev != null && Sets.intersection(prev.getFontNames(), line.getFontNames()).isEmpty()) {
String[] words = line.toText().split(" ");
int cWordsCount = 0;
int wordsCount = 0;
for (String s : words) {
if (s.matches(".*[a-zA-Z].*")) {
wordsCount++;
}
if (s.matches("[A-Z].*")) {
cWordsCount++;
}
}
if (line.toText().contains(",") && (double) cWordsCount / (double) wordsCount > 0.7) {
wasAuthor = true;
}
}
if (wasAuthor) {
z2.addLine(line);
b2.expand(line.getBounds());
} else {
z1.addLine(line);
b1.expand(line.getBounds());
}
prev = line;
}
z1.setBounds(b1.getBounds());
z2.setBounds(b2.getBounds());
if (z1.hasChildren() && z2.hasChildren()) {
toDel = zone;
toAdd1 = z1;
toAdd2 = z2;
}
}
if (toDel != null) {
List<BxZone> list = new ArrayList<BxZone>();
list.addAll(Lists.newArrayList(document.getFirstChild()));
list.remove(toDel);
list.add(toAdd1);
list.add(toAdd2);
document.getFirstChild().setZones(list);
try {
roResolver.resolve(document);
} catch (AnalysisException ex) {}
}
return false;
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.noneOf(EnhancedField.class);
}
}
| 4,691 | 35.092308 | 108 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/JournalEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.EnumSet;
import java.util.Set;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class JournalEnhancer extends AbstractPatternEnhancer {
private static final Pattern PATTERN = Pattern.compile("[^,;]*journal[^,;-]*", Pattern.CASE_INSENSITIVE);
private static final Set<BxZoneLabel> SEARCHED_ZONE_LABELS = EnumSet.of(BxZoneLabel.MET_BIB_INFO);
public JournalEnhancer() {
super(PATTERN, SEARCHED_ZONE_LABELS);
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.JOURNAL);
}
@Override
protected boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata) {
metadata.setJournal(result.group().trim()
.replaceAll("Published as: ", "").replaceAll(",$", ""));
return true;
}
}
| 1,831 | 34.230769 | 109 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/HindawiCornerInfoEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.EnumSet;
import java.util.Set;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* @author Krzysztof Rusek
*/
public class HindawiCornerInfoEnhancer extends AbstractPatternEnhancer {
private static final Pattern PATTERN = Pattern.compile(
"(.+)\n(.+)\nVolume \\d+, Article ID \\d+, \\d+ pages\ndoi:.+");
public HindawiCornerInfoEnhancer() {
super(PATTERN);
setSearchedZoneLabels(BxZoneLabel.MET_BIB_INFO);
setSearchedFirstPageOnly(true);
}
@Override
protected boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata) {
metadata.setPublisher(result.group(1));
metadata.setJournal(result.group(2));
return true;
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.JOURNAL, EnhancedField.PUBLISHER);
}
}
| 1,819 | 32.090909 | 86 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/PagesPartialEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.EnumSet;
import java.util.Set;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxDocument;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
import pl.edu.icm.cermine.tools.CharacterUtils;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class PagesPartialEnhancer extends AbstractPatternEnhancer {
private static final Pattern PATTERN = Pattern.compile(
"(\\d{1,5})[" + String.valueOf(CharacterUtils.DASH_CHARS) + "](\\d{1,5})",
Pattern.CASE_INSENSITIVE);
private int pages = 10;
public PagesPartialEnhancer() {
super(PATTERN);
setSearchedZoneLabels(BxZoneLabel.MET_BIB_INFO);
}
@Override
protected boolean enhanceMetadata(BxDocument document, DocumentMetadata metadata) {
pages = document.childrenCount();
return super.enhanceMetadata(document, metadata);
}
@Override
protected boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata) {
int first = Integer.parseInt(result.group(1));
int last = Integer.parseInt(result.group(2));
if (first <= last && last - first + 1 <= 2 * pages) {
metadata.setPages(result.group(1), result.group(2));
return true;
} else {
return false;
}
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.PAGES);
}
}
| 2,357 | 33.173913 | 87 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/AbstractMultiPatternEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.Collection;
import java.util.List;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxDocument;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public abstract class AbstractMultiPatternEnhancer extends AbstractSimpleEnhancer {
private List<Pattern> patterns;
protected AbstractMultiPatternEnhancer(List<Pattern> patterns, Collection<BxZoneLabel> zoneLabels) {
super(zoneLabels);
this.patterns = patterns;
}
protected AbstractMultiPatternEnhancer(List<Pattern> patterns) {
this.patterns = patterns;
}
protected void setPattern(List<Pattern> patterns) {
this.patterns = patterns;
}
protected abstract boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata);
@Override
protected boolean enhanceMetadata(BxDocument document, DocumentMetadata metadata) {
for (Pattern pattern : patterns) {
for (BxPage page : filterPages(document)) {
for (BxZone zone : filterZones(page)) {
if (enhanceMetadata(zone, pattern, metadata)) {
return true;
}
}
}
}
return false;
}
protected boolean enhanceMetadata(BxZone zone, Pattern pattern, DocumentMetadata metadata) {
Matcher matcher = pattern.matcher(zone.toText());
while (matcher.find()) {
if (enhanceMetadata(matcher.toMatchResult(), metadata)) {
return true;
}
}
return false;
}
}
| 2,672 | 33.269231 | 104 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/AuthorAffiliationSplitterEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import pl.edu.icm.cermine.exception.AnalysisException;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.HierarchicalReadingOrderResolver;
import pl.edu.icm.cermine.structure.ReadingOrderResolver;
import pl.edu.icm.cermine.structure.model.BxDocument;
import pl.edu.icm.cermine.structure.model.BxLine;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
import pl.edu.icm.cermine.structure.tools.BxBoundsBuilder;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class AuthorAffiliationSplitterEnhancer extends AbstractSimpleEnhancer {
public AuthorAffiliationSplitterEnhancer() {
setSearchedZoneLabels(EnumSet.of(BxZoneLabel.MET_AUTHOR));
}
private static final Set<String> KEYWORDS = Sets.newHashSet(
"department", "departament", "universit", "institute", "school", "college",
"univ.", "instituto", "facultad", "universidad", "center", "labs"
);
@Override
protected boolean enhanceMetadata(BxDocument document, DocumentMetadata metadata) {
ReadingOrderResolver roResolver = new HierarchicalReadingOrderResolver();
BxZone toDel = null;
BxZone toAdd1 = null;
BxZone toAdd2 = null;
for (BxZone zone : filterZones(document.getFirstChild())) {
String text = zone.toText().toLowerCase(Locale.ENGLISH);
boolean containsAff = false;
for (String keyword : KEYWORDS) {
if (text.contains(keyword)) {
containsAff = true;
}
}
if (containsAff) {
BxZone z1 = new BxZone();
z1.setLabel(BxZoneLabel.MET_AUTHOR);
BxBoundsBuilder b1 = new BxBoundsBuilder();
BxZone z2 = new BxZone();
z2.setLabel(BxZoneLabel.MET_AFFILIATION);
BxBoundsBuilder b2 = new BxBoundsBuilder();
boolean wasAff = false;
for (BxLine line : zone) {
String lineText = line.toText().toLowerCase(Locale.ENGLISH);
for (String keyword : KEYWORDS) {
if (lineText.contains(keyword)) {
wasAff = true;
}
}
if (wasAff) {
z2.addLine(line);
b2.expand(line.getBounds());
} else {
z1.addLine(line);
b1.expand(line.getBounds());
}
}
z1.setBounds(b1.getBounds());
z2.setBounds(b2.getBounds());
if (z1.hasChildren() && z2.hasChildren()) {
toDel = zone;
toAdd1 = z1;
toAdd2 = z2;
}
}
}
if (toDel != null) {
List<BxZone> list = new ArrayList<BxZone>();
list.addAll(Lists.newArrayList(document.getFirstChild()));
list.remove(toDel);
list.add(toAdd1);
list.add(toAdd2);
document.getFirstChild().setZones(list);
try {
roResolver.resolve(document);
} catch (AnalysisException ex) {}
}
return false;
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.noneOf(EnhancedField.class);
}
}
| 4,557 | 36.360656 | 88 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/TitleMergedWithTypeEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import com.google.common.collect.Sets;
import java.util.*;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxLine;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* @author Krzysztof Rusek
*/
public class TitleMergedWithTypeEnhancer extends AbstractSimpleEnhancer {
// All type strings are lowercase to provide case-insensitive matching
private final Set<String> types = Sets.newHashSet(
"case report",
"case study",
"clinical study",
"debate",
"editorial",
"forum",
"full research paper",
"methodology",
"original article",
"original research",
"primary research",
"research",
"research article",
"research paper",
"review",
"review article",
"short article",
"short paper",
"study",
"study protocol",
"technical note"
);
public TitleMergedWithTypeEnhancer() {
setSearchedZoneLabels(BxZoneLabel.MET_TITLE);
setSearchedFirstPageOnly(true);
}
public void setTypes(Collection<String> types) {
this.types.clear();
for (String type : types) {
this.types.add(type.toLowerCase(Locale.ENGLISH));
}
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.TITLE);
}
@Override
protected boolean enhanceMetadata(BxZone zone, DocumentMetadata metadata) {
if (zone.childrenCount() < 2) {
return false;
} else {
Iterator<BxLine> iterator = zone.iterator();
String firstLine = iterator.next().toText().toLowerCase(Locale.ENGLISH);
if (types.contains(firstLine)) {
StringBuilder text = new StringBuilder();
text.append(iterator.next().toText());
while (iterator.hasNext()) {
text.append(" ");
text.append(iterator.next().toText());
}
metadata.setTitle(text.toString());
return true;
} else {
return false;
}
}
}
@Override
protected boolean enhanceMetadata(BxPage page, DocumentMetadata metadata) {
List<BxZone> titleZones = new ArrayList<BxZone>();
for (BxZone zone : filterZones(page)) {
titleZones.add(zone);
}
Collections.sort(titleZones, new Comparator<BxZone>() {
@Override
public int compare(BxZone t1, BxZone t2) {
return Double.compare(t2.getChild(0).getHeight(),
t1.getChild(0).getHeight());
}
});
for (BxZone zone : titleZones) {
if (enhanceMetadata(zone, metadata)) {
return true;
}
}
return false;
}
}
| 3,941 | 31.04878 | 84 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/PublishedDateEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import pl.edu.icm.cermine.metadata.model.DateType;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
/**
* @author Krzysztof Rusek
*/
public class PublishedDateEnhancer extends AbstractDateEnhancer {
public PublishedDateEnhancer() {
super(EnhancedField.PUBLISHED_DATE, "published");
}
@Override
protected void enhanceMetadata(DocumentMetadata metadata, String day, String month, String year) {
metadata.setDate(DateType.PUBLISHED, day, month, year);
}
}
| 1,300 | 33.236842 | 102 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/AbstractSimpleEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.Collection;
import java.util.Set;
import org.apache.commons.collections.CollectionUtils;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxDocument;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* Abstract base class for enhancers that can only succeed or fail - if
* an enhancer extracts, for example, both volume and issue (from text
* "Vol. 1/2"), it can only extract both pieces of information or none of them.
*
* @author Krzysztof Rusek
*/
public abstract class AbstractSimpleEnhancer extends AbstractFilterEnhancer {
protected AbstractSimpleEnhancer() {}
protected AbstractSimpleEnhancer(Collection<BxZoneLabel> zoneLabels) {
setSearchedZoneLabels(zoneLabels);
}
protected boolean enhanceMetadata(BxZone zone, DocumentMetadata metadata) {
return false;
}
protected boolean enhanceMetadata(BxPage page, DocumentMetadata metadata) {
for (BxZone zone : filterZones(page)) {
if (enhanceMetadata(zone, metadata)) {
return true;
}
}
return false;
}
protected boolean enhanceMetadata(BxDocument document, DocumentMetadata metadata) {
for (BxPage page : filterPages(document)) {
if (enhanceMetadata(page, metadata)) {
return true;
}
}
return false;
}
protected abstract Set<EnhancedField> getEnhancedFields();
@Override
public void enhanceMetadata(BxDocument document, DocumentMetadata metadata, Set<EnhancedField> enhancedFields) {
Set<EnhancedField> fieldsToEnhance = getEnhancedFields();
if (!CollectionUtils.containsAny(enhancedFields, fieldsToEnhance)
&& enhanceMetadata(document, metadata)) {
enhancedFields.addAll(fieldsToEnhance);
}
}
}
| 2,790 | 34.782051 | 116 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/RevisedDateEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import pl.edu.icm.cermine.metadata.model.DateType;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
/**
* @author Krzysztof Rusek
*/
public class RevisedDateEnhancer extends AbstractDateEnhancer {
public RevisedDateEnhancer() {
super(EnhancedField.REVISED_DATE, "revised");
}
@Override
protected void enhanceMetadata(DocumentMetadata metadata, String day, String month, String year) {
metadata.setDate(DateType.REVISED, day, month, year);
}
}
| 1,290 | 32.973684 | 102 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/JournalVolumePagesYearEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.EnumSet;
import java.util.Set;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DateType;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxDocument;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
import pl.edu.icm.cermine.tools.CharacterUtils;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class JournalVolumePagesYearEnhancer extends AbstractPatternEnhancer {
private static final Pattern PATTERN =
Pattern.compile("([A-Z].*)\\s*[\\( ](\\d{4})[\\),;]\\s*(\\d+):\\s*(\\d{1,5})[" + String.valueOf(CharacterUtils.DASH_CHARS) + "](\\d{1,5})");
private static final Set<BxZoneLabel> SEARCHED_ZONE_LABELS = EnumSet.of(BxZoneLabel.MET_BIB_INFO);
private int pages = 10;
public JournalVolumePagesYearEnhancer() {
super(PATTERN, SEARCHED_ZONE_LABELS);
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.JOURNAL, EnhancedField.VOLUME, EnhancedField.PAGES);
}
@Override
protected boolean enhanceMetadata(BxDocument document, DocumentMetadata metadata) {
pages = document.childrenCount();
return super.enhanceMetadata(document, metadata);
}
@Override
protected boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata) {
int first = Integer.parseInt(result.group(4));
int last = Integer.parseInt(result.group(5));
if (first <= last && last - first < pages * 2) {
metadata.setJournal(result.group(1).trim()
.replaceAll("Published as: ", "").replaceAll(",$", ""));
if (metadata.getDate(DateType.PUBLISHED) == null) {
metadata.setDate(DateType.PUBLISHED, null, null, result.group(2));
}
metadata.setVolume(result.group(3));
metadata.setPages(result.group(4), result.group(5));
}
return true;
}
}
| 2,850 | 38.054795 | 152 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/AbstractPatternEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.Collection;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* @author Krzysztof Rusek
*/
public abstract class AbstractPatternEnhancer extends AbstractSimpleEnhancer {
private Pattern pattern;
protected AbstractPatternEnhancer(Pattern pattern, Collection<BxZoneLabel> zoneLabels) {
super(zoneLabels);
this.pattern = pattern;
}
protected AbstractPatternEnhancer(Pattern pattern) {
this.pattern = pattern;
}
protected void setPattern(Pattern pattern) {
this.pattern = pattern;
}
protected abstract boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata);
@Override
protected boolean enhanceMetadata(BxZone zone, DocumentMetadata metadata) {
Matcher matcher = pattern.matcher(zone.toText());
while (matcher.find()) {
if(enhanceMetadata(matcher.toMatchResult(), metadata)) {
return true;
}
}
return false;
}
}
| 2,011 | 31.451613 | 94 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/JournalVolumeIssueWithAuthorEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentAuthor;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class JournalVolumeIssueWithAuthorEnhancer extends AbstractPatternEnhancer {
private static final Pattern PATTERN = Pattern.compile("(.*)\\d{4}, (\\d+):(\\d+)");
private static final Set<BxZoneLabel> SEARCHED_ZONE_LABELS = EnumSet.of(BxZoneLabel.MET_BIB_INFO);
public JournalVolumeIssueWithAuthorEnhancer() {
super(PATTERN, SEARCHED_ZONE_LABELS);
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.JOURNAL, EnhancedField.VOLUME, EnhancedField.ISSUE);
}
@Override
protected boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata) {
String journal = result.group(1);
List<String> authors = getAuthorNames(metadata);
if (authors.size() == 1) {
journal = removeFirst(journal, authors.get(0));
}
if (authors.size() == 2) {
journal = removeFirst(journal, authors.get(0));
journal = removeFirst(journal, "and");
journal = removeFirst(journal, authors.get(1));
}
if (authors.size() > 2) {
journal = journal.replaceFirst("^.*et al\\.", "").trim();
}
metadata.setJournal(journal);
metadata.setVolume(result.group(2));
metadata.setIssue(result.group(3));
return true;
}
private String removeFirst(String journal, String prefix) {
if (journal.toLowerCase(Locale.ENGLISH).startsWith(prefix.toLowerCase(Locale.ENGLISH))) {
return journal.substring(prefix.length()).trim();
}
String[] strs = prefix.split(" ");
for (String str : strs) {
if (journal.toLowerCase(Locale.ENGLISH).startsWith(str.toLowerCase(Locale.ENGLISH))) {
return journal.substring(str.length()).trim();
}
}
return journal;
}
private List<String> getAuthorNames(DocumentMetadata metadata) {
List<String> authors = new ArrayList<String>();
for (DocumentAuthor a : metadata.getAuthors()) {
authors.add(a.getName());
}
return authors;
}
}
| 3,371 | 34.494737 | 102 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/JournalWithoutVolumeIssueEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import com.google.common.collect.Lists;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
import pl.edu.icm.cermine.tools.CharacterUtils;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class JournalWithoutVolumeIssueEnhancer extends AbstractMultiPatternEnhancer {
private static final List<Pattern> PATTERNS = Lists.newArrayList(
Pattern.compile("^([A-Z][^0-9]*) (\\d{1,3})[,: ]+(\\d+)(?=[^\\d" + String.valueOf(CharacterUtils.DASH_CHARS) + "]|$)"),
Pattern.compile("^([A-Z][^0-9]*).*[^0-9](\\d{1,3})[,: ]*\\((\\d+)\\)")
);
private static final Set<BxZoneLabel> SEARCHED_ZONE_LABELS = EnumSet.of(BxZoneLabel.MET_BIB_INFO);
public JournalWithoutVolumeIssueEnhancer() {
super(PATTERNS, SEARCHED_ZONE_LABELS);
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.JOURNAL);
}
@Override
protected boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata) {
metadata.setJournal(result.group(1).trim()
.replaceAll("Published as: ", "").replaceAll(",$", ""));
metadata.setVolume(result.group(2));
metadata.setIssue(result.group(3));
return true;
}
}
| 2,277 | 35.741935 | 131 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/PagesNumbersEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import com.google.common.collect.Lists;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxDocument;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class PagesNumbersEnhancer extends AbstractFilterEnhancer {
public PagesNumbersEnhancer() {
setSearchedZoneLabels(BxZoneLabel.GEN_OTHER, BxZoneLabel.MET_BIB_INFO);
setSearchedFirstPageOnly(false);
}
@Override
public void enhanceMetadata(BxDocument document, DocumentMetadata metadata, Set<EnhancedField> enhancedFields) {
if (enhancedFields.contains(EnhancedField.PAGES)) {
return;
}
List<BxPage> pages = Lists.newArrayList(document);
Map<Integer, Set<Integer>> candidates = new HashMap<Integer, Set<Integer>>();
for (int i = 0; i < pages.size(); i++) {
candidates.put(i, new HashSet<Integer>());
Iterator<BxZone> pageZones = this.filterZones(pages.get(i)).iterator();
while (pageZones.hasNext()) {
BxZone zone = pageZones.next();
if (zone.toText().matches("^\\d{1,6}$")) {
int pageNumber = Integer.parseInt(zone.toText());
candidates.get(i).add(pageNumber);
} else if (zone.childrenCount() == 1) {
Pattern p1 = Pattern.compile("^(\\d{1,6}).*$");
Matcher m1 = p1.matcher(zone.toText());
Pattern p2 = Pattern.compile("^.*(\\d{1,6})$");
Matcher m2 = p2.matcher(zone.toText());
if (m1.matches()) {
int pageNumber = Integer.parseInt(m1.group(1));
candidates.get(i).add(pageNumber);
}
if (m2.matches()) {
int pageNumber = Integer.parseInt(m2.group(1));
candidates.get(i).add(pageNumber);
}
}
}
}
Map<Integer, Integer> candidates1 = new HashMap<Integer, Integer>();
for (int i = 0; i < pages.size(); i++) {
Set<Integer> actCandidates = candidates.get(i);
for (Integer actCand : actCandidates) {
int mine = actCand - i;
int ile = 1;
for (int j = i+1; j < pages.size(); j++) {
if (candidates.get(j).contains(mine+j)) {
candidates.get(j).remove(mine+j);
ile++;
}
}
if (mine > 1) {
candidates1.put(mine, ile);
}
}
}
int best = -1;
int bestarg = -1;
for (int index : candidates1.keySet()) {
if (candidates1.get(index) > best && candidates1.get(index) >= 2) {
bestarg = index;
best = candidates1.get(index);
}
}
if (best > -1) {
metadata.setPages(String.valueOf(bestarg),
String.valueOf(bestarg + document.childrenCount()-1));
enhancedFields.add(EnhancedField.PAGES);
}
}
}
| 4,282 | 37.936364 | 116 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/CiteAsEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.bibref.BibReferenceParser;
import pl.edu.icm.cermine.bibref.CRFBibReferenceParser;
import pl.edu.icm.cermine.bibref.model.BibEntry;
import pl.edu.icm.cermine.bibref.model.BibEntryFieldType;
import pl.edu.icm.cermine.exception.AnalysisException;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxDocument;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* @author Krzysztof Rusek
*/
public class CiteAsEnhancer extends AbstractFilterEnhancer {
private static final Pattern PATTERN = Pattern.compile(
"Cite this article as: (.*)",
Pattern.DOTALL);
private BibReferenceParser<BibEntry> referenceParser;
public CiteAsEnhancer() {
setSearchedZoneLabels(BxZoneLabel.MET_BIB_INFO);
try {
referenceParser = CRFBibReferenceParser.getInstance();
} catch (AnalysisException ex) {
referenceParser = null;
}
}
public void setReferenceParser(BibReferenceParser<BibEntry> referenceParser) {
this.referenceParser = referenceParser;
}
@Override
public void enhanceMetadata(BxDocument document, DocumentMetadata metadata, Set<EnhancedField> enhancedFields) {
if (referenceParser == null) {
return;
}
for (BxPage page : filterPages(document)) {
for (BxZone zone : filterZones(page)) {
Matcher matcher = PATTERN.matcher(zone.toText());
if (matcher.find()) {
BibEntry bibEntry;
try {
bibEntry = referenceParser.parseBibReference(matcher.group(1));
} catch (AnalysisException ex) {
return;
}
if (!enhancedFields.contains(EnhancedField.JOURNAL)) {
String value = bibEntry.getFirstFieldValue(BibEntryFieldType.JOURNAL);
if (value != null) {
metadata.setJournal(value);
enhancedFields.add(EnhancedField.JOURNAL);
}
}
if (!enhancedFields.contains(EnhancedField.VOLUME)) {
String value = bibEntry.getFirstFieldValue(BibEntryFieldType.VOLUME);
if (value != null) {
metadata.setVolume(value);
enhancedFields.add(EnhancedField.VOLUME);
}
}
if (!enhancedFields.contains(EnhancedField.ISSUE)) {
String value = bibEntry.getFirstFieldValue(BibEntryFieldType.NUMBER);
if (value != null) {
metadata.setIssue(value);
enhancedFields.add(EnhancedField.ISSUE);
}
}
}
}
}
}
}
| 3,988 | 38.49505 | 116 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/EnhancedField.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
/**
* @author Krzysztof Rusek
*/
public enum EnhancedField {
ACCEPTED_DATE,
AFFILIATION,
ARTICLE_ID,
AUTHORS,
DESCRIPTION,
DOI,
EDITOR,
EMAIL,
ISSN,
ISSUE,
JOURNAL,
KEYWORDS,
PAGES,
PUBLISHED_DATE,
PUBLISHER,
RECEIVED_DATE,
REVISED_DATE,
TITLE,
URN,
VOLUME;
}
| 1,162 | 16.621212 | 78 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/RevisedFormDateEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import pl.edu.icm.cermine.metadata.model.DateType;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class RevisedFormDateEnhancer extends AbstractDateEnhancer {
public RevisedFormDateEnhancer() {
super(EnhancedField.REVISED_DATE, "revised form");
}
@Override
protected void enhanceMetadata(DocumentMetadata metadata, String day, String month, String year) {
metadata.setDate(DateType.REVISED, day, month, year);
}
}
| 1,327 | 33.947368 | 102 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/TitleAuthorSplitterEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import pl.edu.icm.cermine.exception.AnalysisException;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.HierarchicalReadingOrderResolver;
import pl.edu.icm.cermine.structure.ReadingOrderResolver;
import pl.edu.icm.cermine.structure.model.BxDocument;
import pl.edu.icm.cermine.structure.model.BxLine;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
import pl.edu.icm.cermine.structure.tools.BxBoundsBuilder;
/**
* @author Krzysztof Rusek
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class TitleAuthorSplitterEnhancer extends AbstractSimpleEnhancer {
public TitleAuthorSplitterEnhancer() {
setSearchedZoneLabels(EnumSet.of(BxZoneLabel.MET_TITLE, BxZoneLabel.MET_TITLE_AUTHOR));
}
@Override
protected boolean enhanceMetadata(BxDocument document, DocumentMetadata metadata) {
for (BxZone zone : document.getFirstChild()) {
if (BxZoneLabel.MET_AUTHOR.equals(zone.getLabel())) {
return false;
}
}
ReadingOrderResolver roResolver = new HierarchicalReadingOrderResolver();
BxZone toDel = null;
BxZone toAdd1 = null;
BxZone toAdd2 = null;
for (BxZone zone : filterZones(document.getFirstChild())) {
BxZone z1 = new BxZone();
z1.setLabel(BxZoneLabel.MET_TITLE);
BxBoundsBuilder b1 = new BxBoundsBuilder();
BxZone z2 = new BxZone();
z2.setLabel(BxZoneLabel.MET_AUTHOR);
BxBoundsBuilder b2 = new BxBoundsBuilder();
boolean wasAuthor = false;
BxLine prev = null;
for (BxLine line : zone) {
if (prev != null && Sets.intersection(prev.getFontNames(), line.getFontNames()).isEmpty()) {
String[] words = line.toText().split(" ");
int cWordsCount = 0;
int wordsCount = 0;
for (String s : words) {
if (s.matches(".*[a-zA-Z].*")) {
wordsCount++;
}
if (s.matches("[A-Z].*")) {
cWordsCount++;
}
}
if (line.toText().contains(",") && (double) cWordsCount / (double) wordsCount > 0.7) {
wasAuthor = true;
}
}
if (wasAuthor) {
z2.addLine(line);
b2.expand(line.getBounds());
} else {
z1.addLine(line);
b1.expand(line.getBounds());
}
prev = line;
}
z1.setBounds(b1.getBounds());
z2.setBounds(b2.getBounds());
if (z1.hasChildren() && z2.hasChildren()) {
toDel = zone;
toAdd1 = z1;
toAdd2 = z2;
}
}
if (toDel != null) {
List<BxZone> list = new ArrayList<BxZone>();
list.addAll(Lists.newArrayList(document.getFirstChild()));
list.remove(toDel);
list.add(toAdd1);
list.add(toAdd2);
document.getFirstChild().setZones(list);
try {
roResolver.resolve(document);
} catch (AnalysisException ex) {}
}
return false;
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.noneOf(EnhancedField.class);
}
}
| 4,640 | 35.833333 | 108 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/YearEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import com.google.common.collect.Lists;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DateType;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
import pl.edu.icm.cermine.tools.TextUtils;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class YearEnhancer extends AbstractMultiPatternEnhancer {
private static final List<Pattern> PATTERNS = Lists.newArrayList(
Pattern.compile("(?<=\\s|^)(\\d\\d\\d\\d)(?=\\s|$)"),
Pattern.compile("(?<=\\s|^)(\\d\\d\\d\\d)\\b"),
Pattern.compile("\\b(\\d\\d\\d\\d)\\b")
);
private static final Set<BxZoneLabel> SEARCHED_ZONE_LABELS = EnumSet.of(BxZoneLabel.MET_BIB_INFO);
private static final int MIN_YEAR = 1800;
private static final int MAX_YEAR = 2100;
public YearEnhancer() {
super(PATTERNS, SEARCHED_ZONE_LABELS);
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.PUBLISHED_DATE);
}
@Override
protected boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata) {
for (int i = 1; i <= result.groupCount(); i++) {
String year = result.group(i);
if (TextUtils.isNumberBetween(year, MIN_YEAR, MAX_YEAR)) {
if (metadata.getDate(DateType.PUBLISHED) == null) {
metadata.setDate(DateType.PUBLISHED, null, null, year);
}
return true;
}
}
return false;
}
}
| 2,509 | 34.857143 | 102 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/PagesEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.EnumSet;
import java.util.Set;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxDocument;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
import pl.edu.icm.cermine.tools.CharacterUtils;
/**
* @author Krzysztof Rusek
*/
public class PagesEnhancer extends AbstractPatternEnhancer {
private static final Pattern PATTERN = Pattern.compile(
"\\bpp[\\s:-]\\s*(\\d{1,5})[" + String.valueOf(CharacterUtils.DASH_CHARS) + "](\\d{1,5})",
Pattern.CASE_INSENSITIVE);
private int pages = 10;
public PagesEnhancer() {
super(PATTERN);
setSearchedZoneLabels(BxZoneLabel.MET_BIB_INFO);
}
@Override
protected boolean enhanceMetadata(BxDocument document, DocumentMetadata metadata) {
pages = document.childrenCount();
return super.enhanceMetadata(document, metadata);
}
@Override
protected boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata) {
int first = Integer.parseInt(result.group(1));
int last = Integer.parseInt(result.group(2));
if (first <= last && Math.abs(last - first + 1 - pages) <= 3) {
metadata.setPages(result.group(1), result.group(2));
return true;
} else {
return false;
}
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.PAGES);
}
}
| 2,344 | 32.985507 | 102 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/ArticleIdEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.EnumSet;
import java.util.Set;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.metadata.model.IDType;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* @author Krzysztof Rusek
*/
public class ArticleIdEnhancer extends AbstractPatternEnhancer {
private static final Pattern PATTERN = Pattern.compile("\\barticle id[:-]? (\\d+)", Pattern.CASE_INSENSITIVE);
public ArticleIdEnhancer() {
super(PATTERN, EnumSet.of(BxZoneLabel.MET_BIB_INFO));
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.ARTICLE_ID);
}
@Override
protected boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata) {
metadata.addId(IDType.HINDAWI, result.group(1));
return true;
}
}
| 1,715 | 32.647059 | 114 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/JournalVolumeIssueExtendedEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.EnumSet;
import java.util.Set;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
import pl.edu.icm.cermine.tools.CharacterUtils;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class JournalVolumeIssueExtendedEnhancer extends AbstractPatternEnhancer {
private static final Pattern PATTERN = Pattern.compile("^([A-Z][^0-9]*)[,;: \\d]* (volume|vol|v)[\\.,;: ]+(\\d{1,3})[\\.,;: ]*(issue|num|no|number|n)[\\.,;: ]+(\\d{1,3})(?=[^\\d" + String.valueOf(CharacterUtils.DASH_CHARS) + "]|$)",
Pattern.CASE_INSENSITIVE);
private static final Set<BxZoneLabel> SEARCHED_ZONE_LABELS = EnumSet.of(BxZoneLabel.MET_BIB_INFO);
public JournalVolumeIssueExtendedEnhancer() {
super(PATTERN, SEARCHED_ZONE_LABELS);
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.JOURNAL);
}
@Override
protected boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata) {
metadata.setJournal(result.group(1).trim()
.replaceAll("Published as: ", "").replaceAll(",$", ""));
metadata.setVolume(result.group(3));
metadata.setIssue(result.group(5));
return true;
}
}
| 2,181 | 37.280702 | 236 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/VolumeEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.EnumSet;
import java.util.Set;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* @author Krzysztof Rusek
*/
public class VolumeEnhancer extends AbstractPatternEnhancer {
private static final Pattern PATTERN = Pattern.compile("\\b(?:volume|vol|v)\\.?[\\s:-]\\s*(\\d+)",
Pattern.CASE_INSENSITIVE);
private static final Set<BxZoneLabel> SEARCHED_ZONE_LABELS = EnumSet.of(BxZoneLabel.MET_BIB_INFO);
public VolumeEnhancer() {
super(PATTERN, SEARCHED_ZONE_LABELS);
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.VOLUME);
}
@Override
protected boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata) {
metadata.setVolume(result.group(1));
return true;
}
}
| 1,754 | 32.75 | 102 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/KeywordsEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.*;
/**
* @author Krzysztof Rusek
*/
public class KeywordsEnhancer extends AbstractSimpleEnhancer {
private static final Pattern PREFIX = Pattern.compile("^key\\s?words[:-—]?|^index terms[:-—]?", Pattern.CASE_INSENSITIVE);
public KeywordsEnhancer() {
setSearchedZoneLabels(EnumSet.of(BxZoneLabel.MET_KEYWORDS));
setSearchedFirstPageOnly(true);
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.KEYWORDS);
}
@Override
protected boolean enhanceMetadata(BxDocument document, DocumentMetadata metadata) {
for (BxPage page : filterPages(document)) {
for (BxZone zone : filterZones(page)) {
String text = zone.toText().replace("\n", "<eol>");
text = PREFIX.matcher(text).replaceFirst("");
if (text.matches(".*[:;,.·—].*")) {
String separator = "[:;,.·—]";
for (String keyword : text.split(separator)) {
metadata.addKeyword(keyword.trim().replaceFirst("\\.$", "").replace("-<eol>", "").replace("<eol>", " "));
}
return true;
}
List<String> keywords = new ArrayList<String>();
for (BxLine line : zone) {
List<BxWord> words = new ArrayList<BxWord>();
for (BxWord word : line) {
words.add(word);
}
if (PREFIX.matcher(words.get(0).toText()).matches()) {
words.remove(0);
} else if (words.size() > 1 && PREFIX.matcher(words.get(0).toText()+" "+words.get(1).toText()).matches()) {
words.remove(0);
words.remove(0);
}
if (words.isEmpty()) {
continue;
}
if (words.get(0).toText().charAt(0) >= 'a' && words.get(0).toText().charAt(0) <= 'z' && !keywords.isEmpty()) {
String concat = keywords.get(keywords.size()-1)+" "+words.get(0).toText();
keywords.remove(keywords.size()-1);
keywords.add(concat);
} else {
keywords.add(words.get(0).toText());
}
for (BxWord word : words) {
if (words.indexOf(word) < words.size() - 1) {
double space = word.getNext().getX()-word.getX()-word.getWidth();
if (space > 6) {
keywords.add(word.getNext().toText());
} else {
String concat = keywords.get(keywords.size()-1)+" "+word.getNext().toText();
keywords.remove(keywords.size()-1);
keywords.add(concat);
}
}
}
}
for (String keyword : keywords) {
metadata.addKeyword(keyword.trim().replaceFirst("\\.$", ""));
}
}
}
return false;
}
}
| 4,390 | 40.424528 | 130 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/JournalYearVolumeEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.EnumSet;
import java.util.Set;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DateType;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class JournalYearVolumeEnhancer extends AbstractPatternEnhancer {
private static final Pattern PATTERN =
Pattern.compile("([A-Z][^0-9\\(\\)]*)\\(?(\\d{4})\\)?[\\.,: ]+[A-Z]?(\\d+)");
private static final Set<BxZoneLabel> SEARCHED_ZONE_LABELS = EnumSet.of(BxZoneLabel.MET_BIB_INFO);
public JournalYearVolumeEnhancer() {
super(PATTERN, SEARCHED_ZONE_LABELS);
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.JOURNAL, EnhancedField.PUBLISHED_DATE, EnhancedField.VOLUME);
}
@Override
protected boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata) {
metadata.setJournal(result.group(1).trim()
.replaceAll("Published as: ", "").replaceAll(",$", ""));
if (metadata.getDate(DateType.PUBLISHED) == null) {
metadata.setDate(DateType.PUBLISHED, null, null, result.group(2));
}
metadata.setVolume(result.group(3));
return true;
}
}
| 2,181 | 35.983051 | 102 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/AuthorAffiliationGeometricEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import com.google.common.collect.Lists;
import java.util.EnumSet;
import java.util.Set;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxDocument;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class AuthorAffiliationGeometricEnhancer extends AbstractSimpleEnhancer {
public AuthorAffiliationGeometricEnhancer() {
setSearchedZoneLabels(BxZoneLabel.MET_AFFILIATION);
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.AUTHORS, EnhancedField.AFFILIATION);
}
@Override
protected boolean enhanceMetadata(BxDocument document, DocumentMetadata metadata) {
BxPage page = document.getFirstChild();
for (BxZone zone : page) {
if (zone.getY() < page.getHeight()/2 && zone.getLabel().equals(BxZoneLabel.MET_AUTHOR)) {
return false;
}
}
boolean inLine = false;
for (BxZone zone1 : filterZones(page)) {
for (BxZone zone2 : filterZones(page)) {
if (!zone1.equals(zone2) && Math.abs(zone1.getY()-zone2.getY()) < 10) {
inLine = true;
}
}
}
if (!inLine) {
return false;
}
boolean added = false;
int ind = 0;
for (BxZone zone : filterZones(page)) {
if (zone.getY() > page.getHeight() / 2 && zone.hasPrev() && zone.getPrev().toText().equals("Keywords")) {
continue;
}
String authorText = zone.getFirstChild().toText();
String emailText = null;
StringBuilder sb = new StringBuilder();
int j = zone.childrenCount();
for (int i = 1; i < zone.childrenCount(); i++) {
String lineText = zone.getChild(i).toText();
if (lineText.matches(".*@.*")) {
if (i == 1) {
emailText = lineText;
continue;
} else {
j = i;
break;
}
}
if (lineText.endsWith("-")) {
sb.append(lineText.replaceAll("-$", ""));
} else if (lineText.endsWith(",")) {
sb.append(lineText);
sb.append(" ");
} else {
sb.append(lineText);
sb.append(", ");
}
}
String affText = sb.toString().trim().replaceAll(",$", "");
if (emailText == null) {
sb = new StringBuilder();
for (int i = j; i < zone.childrenCount(); i++) {
String lineText = zone.getChild(i).toText();
if (lineText.endsWith("-")) {
sb.append(lineText.replaceAll("-$", ""));
} else {
sb.append(lineText);
sb.append(" ");
}
}
emailText = sb.toString().trim();
}
if (authorText.isEmpty() || affText.isEmpty()) {
continue;
}
emailText = emailText
.replaceFirst("^[Ee]mails?: *", "")
.replaceFirst("^[Ee]- *[Mm]ails?: *", "");
metadata.addAuthor(authorText, Lists.newArrayList(String.valueOf(ind)), emailText);
metadata.setAffiliationByIndex(String.valueOf(ind), affText);
added = true;
ind++;
}
return added;
}
}
| 4,702 | 34.628788 | 117 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/Enhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.Set;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxDocument;
/**
* @author Krzysztof Rusek
*/
public interface Enhancer {
/**
* Extracts metadata from the document and puts it into metadata object.
*
* @param document segmented and classified document
* @param metadata metadata object containing metadata already extracted
* by other enhancers; newly extracted metadata are added to this object
* @param enhancedFields set of fields enhanced already enhanced by other
* enhancers; newly enhanced fields are added be added to this set
*/
void enhanceMetadata(BxDocument document, DocumentMetadata metadata, Set<EnhancedField> enhancedFields);
}
| 1,567 | 37.243902 | 108 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/PagesLastEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.EnumSet;
import java.util.Set;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxDocument;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
import pl.edu.icm.cermine.tools.CharacterUtils;
/**
* @author Krzysztof Rusek
*/
public class PagesLastEnhancer extends AbstractPatternEnhancer {
private static final Pattern PATTERN = Pattern.compile(
"(\\d{1,5})[" + String.valueOf(CharacterUtils.DASH_CHARS) + "](\\d{1,5})",
Pattern.CASE_INSENSITIVE);
private int pages = 10;
public PagesLastEnhancer() {
super(PATTERN);
setSearchedZoneLabels(BxZoneLabel.MET_BIB_INFO);
}
@Override
protected boolean enhanceMetadata(BxDocument document, DocumentMetadata metadata) {
pages = document.childrenCount();
return super.enhanceMetadata(document, metadata);
}
@Override
protected boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata) {
int first = Integer.parseInt(result.group(1));
int last = Integer.parseInt(result.group(2));
if (first <= last && last - first + 1 <= 2 * pages) {
metadata.setPages(result.group(1), result.group(2));
return true;
} else {
return false;
}
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.PAGES);
}
}
| 2,326 | 32.724638 | 87 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/JournalVolumePagesEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.EnumSet;
import java.util.Set;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.model.BxDocument;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
import pl.edu.icm.cermine.tools.CharacterUtils;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class JournalVolumePagesEnhancer extends AbstractPatternEnhancer {
private static final Pattern PATTERN =
Pattern.compile("([A-Z][^\\d]*),?\\s+(\\d+):?\\s*(\\d{1,5})[" + String.valueOf(CharacterUtils.DASH_CHARS) + "](\\d{1,5})");
private static final Set<BxZoneLabel> SEARCHED_ZONE_LABELS = EnumSet.of(BxZoneLabel.MET_BIB_INFO);
private int pages = 10;
public JournalVolumePagesEnhancer() {
super(PATTERN, SEARCHED_ZONE_LABELS);
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.of(EnhancedField.JOURNAL, EnhancedField.VOLUME, EnhancedField.PAGES);
}
@Override
protected boolean enhanceMetadata(BxDocument document, DocumentMetadata metadata) {
pages = document.childrenCount();
return super.enhanceMetadata(document, metadata);
}
@Override
protected boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata) {
int first = Integer.parseInt(result.group(3));
int last = Integer.parseInt(result.group(4));
if (first <= last && last - first < pages * 2) {
metadata.setJournal(result.group(1).trim()
.replaceAll("Published as: ", "").replaceAll(",$", ""));
metadata.setVolume(result.group(2));
metadata.setPages(result.group(3), result.group(4));
return true;
}
return false;
}
}
| 2,639 | 36.714286 | 135 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/AffiliationAuthorSplitterEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import pl.edu.icm.cermine.exception.AnalysisException;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
import pl.edu.icm.cermine.structure.HierarchicalReadingOrderResolver;
import pl.edu.icm.cermine.structure.ReadingOrderResolver;
import pl.edu.icm.cermine.structure.model.BxDocument;
import pl.edu.icm.cermine.structure.model.BxLine;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
import pl.edu.icm.cermine.structure.tools.BxBoundsBuilder;
/**
* @author Krzysztof Rusek
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class AffiliationAuthorSplitterEnhancer extends AbstractSimpleEnhancer {
public AffiliationAuthorSplitterEnhancer() {
setSearchedZoneLabels(EnumSet.of(BxZoneLabel.MET_AFFILIATION));
}
private static final Set<String> KEYWORDS = Sets.newHashSet(
"department", "departament", "universit", "institute", "school", "college",
"univ.", "instituto", "facultad", "universidad", "center", "labs"
);
@Override
protected boolean enhanceMetadata(BxDocument document, DocumentMetadata metadata) {
for (BxZone zone : document.getFirstChild()) {
if (BxZoneLabel.MET_AUTHOR.equals(zone.getLabel())) {
return false;
}
}
boolean inLine = false;
for (BxZone zone1 : filterZones(document.getFirstChild())) {
for (BxZone zone2 : filterZones(document.getFirstChild())) {
if (!zone1.equals(zone2) && Math.abs(zone1.getY()-zone2.getY()) < 10) {
inLine = true;
}
}
}
if (inLine) {
return false;
}
ReadingOrderResolver roResolver = new HierarchicalReadingOrderResolver();
BxZone toDel = null;
BxZone toAdd1 = null;
BxZone toAdd2 = null;
for (BxZone zone : filterZones(document.getFirstChild())) {
BxZone z1 = new BxZone();
z1.setLabel(BxZoneLabel.MET_AUTHOR);
BxBoundsBuilder b1 = new BxBoundsBuilder();
BxZone z2 = new BxZone();
z2.setLabel(BxZoneLabel.MET_AFFILIATION);
BxBoundsBuilder b2 = new BxBoundsBuilder();
boolean wasAff = false;
BxLine prev = null;
for (BxLine line : zone) {
String lineText = line.toText().toLowerCase(Locale.ENGLISH);
if (prev != null &&
(!prev.getMostPopularFontName().equals(line.getMostPopularFontName())
|| prev.getHeight() - line.getHeight() > 1)) {
for (String keyword : KEYWORDS) {
if (lineText.contains(keyword)) {
wasAff = true;
}
}
}
if (wasAff) {
z2.addLine(line);
b2.expand(line.getBounds());
} else {
z1.addLine(line);
b1.expand(line.getBounds());
}
prev = line;
}
z1.setBounds(b1.getBounds());
z2.setBounds(b2.getBounds());
if (z1.hasChildren() && z2.hasChildren()) {
toDel = zone;
toAdd1 = z1;
toAdd2 = z2;
}
}
if (toDel != null) {
List<BxZone> list = new ArrayList<BxZone>();
list.addAll(Lists.newArrayList(document.getFirstChild()));
list.remove(toDel);
list.add(toAdd1);
list.add(toAdd2);
document.getFirstChild().setZones(list);
try {
roResolver.resolve(document);
} catch (AnalysisException ex) {}
}
return false;
}
@Override
protected Set<EnhancedField> getEnhancedFields() {
return EnumSet.noneOf(EnhancedField.class);
}
}
| 5,038 | 36.051471 | 93 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/AbstractFilterEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import java.util.*;
import pl.edu.icm.cermine.structure.model.BxDocument;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* Abstract enhancer with page and zone filtering implementation.
*
* @author Krzysztof Rusek
*/
public abstract class AbstractFilterEnhancer implements Enhancer {
private boolean searchedFirstPageOnly = false;
private final Set<BxZoneLabel> searchedZoneLabels = EnumSet.allOf(BxZoneLabel.class);
public void setSearchedFirstPageOnly(boolean value) {
searchedFirstPageOnly = value;
}
public final void setSearchedZoneLabels(Collection<BxZoneLabel> zoneLabels) {
searchedZoneLabels.clear();
searchedZoneLabels.addAll(zoneLabels);
}
public void setSearchedZoneLabels(BxZoneLabel... zoneLabels) {
setSearchedZoneLabels(Arrays.asList(zoneLabels));
}
protected Iterable<BxZone> filterZones(BxPage page) {
return new FilterIterable<BxZone>(page) {
@Override
protected boolean match(BxZone zone) {
return searchedZoneLabels.contains(zone.getLabel());
}
};
}
protected Iterable<BxPage> filterPages(BxDocument document) {
return new FilterIterable<BxPage>(document) {
@Override
protected boolean match(BxPage page) {
return !searchedFirstPageOnly || !page.hasPrev();
}
};
}
private abstract static class FilterIterable<T> implements Iterable<T> {
private final Iterable<T> it;
public FilterIterable(Iterable<T> it) {
this.it = it;
}
protected abstract boolean match(T zone);
@Override
public Iterator<T> iterator() {
return new Iterator<T>() {
private final Iterator<T> iterator;
private T next = null;
{
iterator = it.iterator();
findNext();
}
private void findNext() {
if (!iterator.hasNext()) {
next = null;
}
while (iterator.hasNext()) {
next = iterator.next();
if (match(next)) {
break;
}
}
if (next != null && !iterator.hasNext() && !match(next)) {
next = null;
}
}
@Override
public boolean hasNext() {
return next != null;
}
@Override
public T next() {
T ret = this.next;
findNext();
return ret;
}
@Override
public void remove() {
}
};
}
}
}
| 3,839 | 29 | 89 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/AcceptedDateEnhancer.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.extraction.enhancers;
import pl.edu.icm.cermine.metadata.model.DateType;
import pl.edu.icm.cermine.metadata.model.DocumentMetadata;
/**
* @author Krzysztof Rusek
*/
public class AcceptedDateEnhancer extends AbstractDateEnhancer {
public AcceptedDateEnhancer() {
super(EnhancedField.ACCEPTED_DATE, "accepted");
}
@Override
protected void enhanceMetadata(DocumentMetadata metadata, String day, String month, String year) {
metadata.setDate(DateType.ACCEPTED, day, month, year);
}
}
| 1,296 | 32.25641 | 102 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/tools/MetadataTools.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.tools;
import java.text.Normalizer;
import pl.edu.icm.cermine.content.cleaning.ContentCleaner;
/**
* @author Krzysztof Rusek
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class MetadataTools {
public static String cleanAndNormalize(String str) {
return Normalizer.normalize(ContentCleaner.cleanAllAndBreaks(str), Normalizer.Form.NFKD);
}
}
| 1,149 | 32.823529 | 97 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/tools/ZoneClassificationUtils.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.tools;
import java.util.Map;
import pl.edu.icm.cermine.structure.model.BxDocument;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
import pl.edu.icm.cermine.structure.tools.BxBoundsBuilder;
/**
* Zone classification utility class.
*
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class ZoneClassificationUtils {
private static final String[] CONJUNCTIONS = {"and", "or", "for", "or", "nor"};
public static boolean isConjunction(String word) {
for (String conjunction : CONJUNCTIONS) {
if (conjunction.equalsIgnoreCase(word)) {
return true;
}
}
return false;
}
public static void mapZoneLabels(BxDocument document, Map<BxZoneLabel, BxZoneLabel> labelMap) {
for (BxPage page : document) {
for (BxZone zone : page) {
if (labelMap.get(zone.getLabel()) != null) {
zone.setLabel(labelMap.get(zone.getLabel()));
}
}
}
}
public static void correctPagesBounds(BxDocument document) {
BxBoundsBuilder builder = new BxBoundsBuilder();
for (BxPage page : document) {
builder.expand(page.getBounds());
}
for (BxPage page : document) {
page.setBounds(builder.getBounds());
}
}
}
| 2,234 | 32.863636 | 99 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/tools/ZoneLocaliser.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.tools;
import pl.edu.icm.cermine.structure.model.BxZone;
/**
* @author Pawel Szostek
*/
public class ZoneLocaliser {
private BxZone leftZone = null;
private BxZone rightZone = null;
private BxZone upperZone = null;
private BxZone lowerZone = null;
public ZoneLocaliser(BxZone zone) {
for (BxZone otherZone : zone.getParent()) {
if (otherZone == zone) {
continue;
}
double cx, cy, cw, ch, ox, oy, ow, oh;
cx = zone.getBounds().getX();
cy = zone.getBounds().getY();
cw = zone.getBounds().getWidth();
ch = zone.getBounds().getHeight();
ox = otherZone.getBounds().getX();
oy = otherZone.getBounds().getY();
ow = otherZone.getBounds().getWidth();
oh = otherZone.getBounds().getHeight();
// Determine Octant
//
// 0 | 1 | 2
// __|___|__
// 7 | 9 | 3
// __|___|__
// 6 | 5 | 4
int oct;
if (cx + cw <= ox) {
if (cy + ch <= oy) {
oct = 4;
} else if (cy >= oy + oh) {
oct = 2;
} else {
oct = 3;
}
} else if (ox + ow <= cx) {
if (cy + ch <= oy) {
oct = 6;
} else if (oy + oh <= cy) {
oct = 0;
} else {
oct = 7;
}
} else if (cy + ch <= oy) {
oct = 5;
} else { // oy + oh <= cy
oct = 1;
}
switch (oct) {
case 1:
if (upperZone == null || otherZone.getY() + otherZone.getHeight() > upperZone.getY() + upperZone.getHeight()) {
upperZone = otherZone;
} break;
case 5:
if (lowerZone == null || otherZone.getY() < lowerZone.getY()) {
lowerZone = otherZone;
} break;
case 7:
if (leftZone == null || otherZone.getX() + otherZone.getWidth() > leftZone.getX() + leftZone.getWidth()) {
leftZone = otherZone;
} break;
case 3:
if (rightZone == null || otherZone.getX() < rightZone.getX()) {
rightZone = otherZone;
} break;
default:
break;
}
}
}
public BxZone getLeftZone() {
return leftZone;
}
public BxZone getRightZone() {
return rightZone;
}
public BxZone getUpperZone() {
return upperZone;
}
public BxZone getLowerZone() {
return lowerZone;
}
}
| 3,705 | 30.142857 | 131 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/tools/LabelPair.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.tools;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* @author Pawel Szostek
*/
public class LabelPair {
/**
* expected
*/
public BxZoneLabel l1;
/**
* predicted *
*/
public BxZoneLabel l2;
public LabelPair(BxZoneLabel l1, BxZoneLabel l2) {
this.l1 = l1;
this.l2 = l2;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
LabelPair other = (LabelPair) obj;
if (l1 != other.l1) {
return false;
}
return l2 == other.l2;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((l1 == null) ? 0 : l1.hashCode());
result = prime * result + ((l2 == null) ? 0 : l2.hashCode());
return result;
}
@Override
public String toString() {
return "(" + l1 + ", " + l2 + ")";
}
}
| 1,910 | 25.178082 | 78 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/PreviousZoneFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class PreviousZoneFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone object, BxPage context) {
if (object.hasPrev()) {
return (double) object.getPrev().getLabel().ordinal();
} else {
return -1.0;
}
}
}
| 1,334 | 34.131579 | 78 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/BracketedLineRelativeCountFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxLine;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class BracketedLineRelativeCountFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
int lines = 0;
int bracketedLines = 0;
for (BxLine line : zone) {
++lines;
if (line.toText().charAt(0) == '[' || line.toText().charAt(0) == ']') {
++bracketedLines;
}
}
return (double) bracketedLines / (double) lines;
}
}
| 1,554 | 33.555556 | 90 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/BracketRelativeCountFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class BracketRelativeCountFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
double brackets = new BracketCountFeature().calculateFeatureValue(zone, page);
double chars = new CharCountFeature().calculateFeatureValue(zone, page);
return brackets / chars;
}
}
| 1,387 | 37.555556 | 86 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/CharCountFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.*;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class CharCountFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
int count = 0;
for (BxLine line : zone) {
for (BxWord word : line) {
for (BxChunk chunk : word) {
count += chunk.toText().length();
}
}
}
return (double) count;
}
}
| 1,418 | 31.25 | 78 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/ContainsCuePhrasesFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import java.util.Locale;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class ContainsCuePhrasesFeature extends FeatureCalculator<BxZone, BxPage> {
private static final String[] cuePhrases = {"although", "therefore", "therein", "hereby",
"nevertheless", "to this end", "however", "moreover", "nonetheless"};
@Override
public String getFeatureName() {
return "ContainsCuePhrases";
}
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
String zoneText = zone.toText().toLowerCase(Locale.ENGLISH);
for (String cuePhrase : cuePhrases) {
if (zoneText.contains(cuePhrase)) {
return 1.0;
}
}
return 0.0;
}
}
| 1,714 | 32.627451 | 93 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/IsPageNumberFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
/**
* @author Pawel Szostek
*/
public class IsPageNumberFeature extends AbstractFeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone object, BxPage context) {
String text = object.toText();
try {
Integer.valueOf(text);
return 1.0;
} catch (NumberFormatException e) {
return 0.0;
}
}
}
| 1,308 | 31.725 | 84 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/WordLengthMedianFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class WordLengthMedianFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone object, BxPage context) {
String text = object.toText();
String[] words = text.split("\\s");
List<Integer> wordLengths = new ArrayList<Integer>(words.length);
for (String word : words) {
wordLengths.add(word.length());
}
Collections.sort(wordLengths);
return wordLengths.get(wordLengths.size() / 2);
}
}
| 1,611 | 34.822222 | 80 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/AffiliationFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import java.util.Locale;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class AffiliationFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
String[] keywords = {"author details", "university", "department", "school", "affiliation",
"institute", "laboratory", "centre", "center", "faculty"};
int count = 0;
for (String keyword : keywords) {
if (zone.toText().toLowerCase(Locale.ENGLISH).contains(keyword)) {
count++;
}
}
return count;
}
}
| 1,636 | 33.829787 | 100 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/BracketCountFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class BracketCountFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
int bracketCount = 0;
for (char c : zone.toText().toCharArray()) {
if (c == '[' || c == ']') {
++bracketCount;
}
}
return bracketCount;
}
}
| 1,387 | 32.853659 | 78 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/IsLeftFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
/**
* @author Pawel Szostek
*/
public class IsLeftFeature extends AbstractFeatureCalculator<BxZone, BxPage> {
private static final double TRESHOLD = 0.3;
@Override
public double calculateFeatureValue(BxZone object, BxPage context) {
if (object.getX() + object.getWidth() / 2.0 < context.getWidth() * TRESHOLD) {
return 1.0;
} else {
return 0.0;
}
}
}
| 1,323 | 32.1 | 86 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/FreeSpaceWithinZoneFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.*;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class FreeSpaceWithinZoneFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
double charSpace = 0.0;
for (BxLine line : zone) {
for (BxWord word : line) {
for (BxChunk chunk : word) {
charSpace += chunk.getArea();
}
}
}
return zone.getArea() - charSpace;
}
}
| 1,418 | 32 | 83 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/IsItemizeFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class IsItemizeFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
String text = zone.toText();
String itemizeString = "";
itemizeString += "|^\\d+\\.\\d+\\.\\s+\\p{Upper}.+";
itemizeString += "|^\\d+\\.\\s+\\p{Upper}.+";
itemizeString += "|^\\p{Upper}\\.\\s[^\\.]+";
itemizeString += "|^\\p{Lower}\\)\\s+.+";
Pattern itemizePattern = Pattern.compile(itemizeString);
String subpointsString = "";
subpointsString += "^\\d\\.\\d\\.\\s+\\p{Upper}.+";
subpointsString += "|^\\d\\.\\d\\.\\d\\.\\s+\\p{Upper}.+";
Pattern subpointsPattern = Pattern.compile(subpointsString, Pattern.DOTALL); //for multiline matching
Matcher matcher1 = itemizePattern.matcher(text);
Matcher matcher2 = subpointsPattern.matcher(text);
return (matcher1.matches() || matcher2.matches()) ? 1.0 : 0.0;
}
}
| 2,060 | 37.886792 | 109 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/DateFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class DateFeature extends AbstractFeatureCalculator<BxZone, BxPage> {
static final String[] MONTH_REGEXPS = new String[36];
static final String[] DIGIT_REGEXPS = {
"\\d{4}[ \\.-/]\\d{2}[ \\.-/]\\d{2}",
"\\d{2}[ \\.-/]\\d{2}[ \\.-/]\\d{4}"
};
static final String[] MONTHS = { "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december" };
static {
int idx=0;
for(String month: MONTHS) {
MONTH_REGEXPS[idx] = "\\d{4}" + "[ \\.-/]" + month + "[ \\.-/]" + "\\d{2}";
MONTH_REGEXPS[idx+12] = "\\d{2}" + "[ \\.-/]" + month + "[ \\.-/]" + "\\d{4}";
MONTH_REGEXPS[idx+24] = "\\d{4}" + "[ ]" + month.substring(0, 3) + "\\.?[ ]" + "\\d{2}";
++idx;
}
}
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
String text = zone.toText().toLowerCase(Locale.ENGLISH);
for(String regex: MONTH_REGEXPS) {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(text);
if (matcher.find()) {
return 1.0;
}
}
for(String regex: DIGIT_REGEXPS) {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(text);
if (matcher.find()) {
return 1.0;
}
}
return 0.0;
}
}
| 2,322 | 32.185714 | 157 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/AuthorNameRelativeFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
/**
* @author Pawel Szostek
*/
public class AuthorNameRelativeFeature extends AbstractFeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone object, BxPage context) {
String text = object.toText();
String[] parts = text.split(",|and");
int numberOfNames = 0;
if (parts.length == 0) {
return 0;
}
for (String part : parts) {
if (part.length() == 0) {
++numberOfNames;
continue;
}
String[] words = part.split("\\s");
boolean isName = true;
for (String word : words) {
if (word.length() == 1 && word.matches("\\*|")) {
continue;
}
if (word.length() == 2 && word.matches("\\w\\.")) {
continue;
}
if (word.matches("\\d+")) {
continue;
}
if (word.matches("\\p{Upper}.*")) {
continue;
} else if (word.equals("van") || word.equals("von")) {
continue;
}
isName = false;
break;
}
if (isName) {
++numberOfNames;
}
}
return numberOfNames / (double) parts.length;
}
}
| 2,306 | 31.492958 | 90 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/CommaCountFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.*;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class CommaCountFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
int count = 0;
for (BxLine line : zone) {
for (BxWord word : line) {
for (BxChunk chunk : word) {
char[] arr = chunk.toText().toCharArray();
for (int i = 0; i < arr.length; i++) {
if (arr[i]==',') {
count++;
}
}
}
}
}
return (double) count;
}
}
| 1,613 | 33.340426 | 78 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/LetterCountFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.*;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class LetterCountFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
int count = 0;
for (BxLine line : zone) {
for (BxWord word : line) {
for (BxChunk chunk : word) {
char[] arr = chunk.toText().toCharArray();
for (int i = 0; i < arr.length; i++) {
if (Character.isLetter(arr[i])) {
count++;
}
}
}
}
}
return (double) count;
}
}
| 1,629 | 33.680851 | 78 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/EmptySpaceFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.*;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class EmptySpaceFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
double charSpace = 0.0;
for (BxLine line : zone) {
for (BxWord word : line) {
for (BxChunk chunk : word) {
charSpace += chunk.getArea();
}
}
}
double ret = zone.getArea() - charSpace;
return ret < 0 ? 0.0 : ret;
}
}
| 1,450 | 32.744186 | 78 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/AcknowledgementFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import java.util.Locale;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class AcknowledgementFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
String[] keywords = {"acknowledge", "acknowledgement", "acknowledgment"};
for (String keyword : keywords) {
if (zone.toText().toLowerCase(Locale.ENGLISH).contains(keyword)) {
return 1;
}
}
return 0;
}
} | 1,477 | 33.372093 | 81 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/IsAnywhereElseFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import java.util.List;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
/**
* @author Pawel Szostek
*/
public class IsAnywhereElseFeature extends AbstractFeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone object, BxPage context) {
List<BxPage> pages = getOtherPages(context);
if (object.toText().length() <= 5) {
return 0.0;
}
for (BxPage page : pages) {
for (BxZone zone : page) {
if (zone.toText().equals(object.toText())) {
return 1.0;
}
}
}
return 0.0;
}
}
| 1,504 | 32.444444 | 86 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/UppercaseWordRelativeCountFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxLine;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxWord;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class UppercaseWordRelativeCountFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
int count = 0;
int allCount = 0;
for (BxLine line : zone) {
for (BxWord word : line) {
allCount++;
if (word.hasChildren()) {
String s = word.getChild(0).toText();
if (!s.isEmpty() && Character.isUpperCase(s.charAt(0))) {
count++;
}
}
}
}
return (double) count / (double) allCount;
}
}
| 1,781 | 34.64 | 90 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/DotCountFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.*;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class DotCountFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
int count = 0;
for (BxLine line : zone) {
for (BxWord word : line) {
for (BxChunk chunk : word) {
char[] arr = chunk.toText().toCharArray();
for (int i = 0; i < arr.length; i++) {
if (arr[i]=='.') {
count++;
}
}
}
}
}
return (double) count;
}
}
| 1,611 | 33.297872 | 78 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/StartsWithDigitFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class StartsWithDigitFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
if (zone.toText().length() == 0) {
return 0.0;
} else {
return (Character.isDigit(zone.toText().charAt(0))) ? 1.0 : 0.0;
}
}
}
| 1,334 | 32.375 | 79 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/YPositionFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class YPositionFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
return zone.getBounds().getY();
}
}
| 1,243 | 33.555556 | 78 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/CuePhrasesRelativeCountFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class CuePhrasesRelativeCountFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
FeatureCalculator<BxZone, BxPage> cuePhrasesCalc = new ContainsCuePhrasesFeature();
FeatureCalculator<BxZone, BxPage> wordsCalc = new WordCountFeature();
double cuePhrasesCountValue = cuePhrasesCalc.calculateFeatureValue(zone, page);
double wordCountValue = wordsCalc.calculateFeatureValue(zone, page);
return cuePhrasesCountValue / wordCountValue;
}
}
| 1,578 | 40.552632 | 91 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/ReferencesFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.structure.model.BxLine;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class ReferencesFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
int refDigits = 0;
int refIndents = 0;
for (BxLine line : zone) {
if (Pattern.matches("^\\[\\d+\\].*", line.toText()) || Pattern.matches("^\\d+\\..*", line.toText())) {
refDigits++;
}
if (zone.getBounds().getX() + 8 < line.getBounds().getX()) {
refIndents++;
}
}
return ((double)refDigits > (double)zone.childrenCount() / 4.0
|| (double)refIndents > (double)zone.childrenCount() / 4.0) ? 1 : 0;
}
}
| 1,817 | 36.102041 | 114 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/FullWordsRelativeFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.metadata.zoneclassification.tools.ZoneClassificationUtils;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
/**
* @author Pawel Szostek
*/
public class FullWordsRelativeFeature extends AbstractFeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone object, BxPage context) {
String text = object.toText();
String[] words = text.split("\\s");
int numberOfWords = 0;
int numberOfFullWords = 0;
for (String word : words) {
if (ZoneClassificationUtils.isConjunction(word)) {
++numberOfFullWords;
} else if (word.length() > 2 && !word.matches(".*\\d.*") && !word.matches(".*[^\\p{Alnum}].*")) {
++numberOfFullWords;
}
++numberOfWords;
}
return (double) numberOfFullWords / numberOfWords;
}
}
| 1,752 | 36.297872 | 109 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/PageNumberFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class PageNumberFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone object, BxPage context) {
return (double) Integer.parseInt(context.getId());
}
}
| 1,241 | 34.485714 | 78 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/VerticalProminenceFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class VerticalProminenceFeature extends FeatureCalculator<BxZone, BxPage> {
private static final double ZONE_EPSILON = 1.0;
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
if (page.childrenCount() == 1) {
return 0.0; //there is only one zone - no prominence can be measured
}
BxZone prevZone = zone.getPrev();
BxZone nextZone = zone.getNext();
while (true) {
if (prevZone == null) { //given zone is the first one in the set - there is none before it
if (nextZone == null) {
return page.getHeight() - zone.getHeight();
} else if (nextZone.getY() - (zone.getY() + zone.getHeight()) > ZONE_EPSILON) {
return nextZone.getY() - (zone.getY() + zone.getHeight());
} else {
nextZone = nextZone.getNext();
}
} else if (nextZone == null) { //given zone is the last one in the set - there is none after it
if (zone.getY() - (prevZone.getY() + prevZone.getHeight()) > ZONE_EPSILON) {
return zone.getY() - (prevZone.getY() + prevZone.getHeight());
} else {
prevZone = prevZone.getPrev();
}
} else { //there is a zone before and after the given one
if (zone.getY() - (prevZone.getY() + prevZone.getHeight()) > ZONE_EPSILON) { //previous zone lies in the same column
if (nextZone.getY() - (zone.getY() + zone.getHeight()) > ZONE_EPSILON) { //next zone lies in the same column
return nextZone.getY() - (prevZone.getY() + prevZone.getHeight()) - zone.getHeight();
} else {
nextZone = nextZone.getNext();
}
} else {
if (nextZone.getY() - (zone.getY() + zone.getHeight()) > ZONE_EPSILON) {
prevZone = prevZone.getPrev();
} else { //neither previous zone nor next zone lies in natural geometrical order
prevZone = prevZone.getPrev();
nextZone = nextZone.getNext();
}
}
}
}
}
}
| 3,327 | 44.589041 | 132 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/IsLowestOnThePageFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import com.google.common.collect.Lists;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.Utils;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class IsLowestOnThePageFeature extends FeatureCalculator<BxZone, BxPage> {
public static final double EPS = 10.0;
private static class YCoordinateComparator implements Comparator<BxZone> {
@Override
public int compare(BxZone z1, BxZone z2) {
return Utils.compareDouble(z1.getY() + z1.getHeight(), z2.getY() + z2.getHeight(), 0.1);
}
}
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
List<BxZone> zones = Lists.newArrayList(page);
Collections.sort(zones, new YCoordinateComparator());
BxZone lastZone = zones.get(zones.size() - 1);
if (zone.equals(lastZone)) {
return 1.0;
} else if (Math.abs(lastZone.getY() + lastZone.getHeight() - (zone.getY() + zone.getHeight())) <= EPS) {
return 1.0;
} else {
return 0.0;
}
}
}
| 2,076 | 34.810345 | 112 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/IsSingleWordFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
/**
* @author Pawel Szostek
*/
public class IsSingleWordFeature extends AbstractFeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone object, BxPage context) {
String text = object.toText().replaceAll("\\n", " ").replaceAll("\\r", " ").replaceAll(" +", " ");
if (text.isEmpty()) {
return 0.0;
}
return (text.split(" ").length == 1) ? 1 : 0;
}
}
| 1,343 | 34.368421 | 106 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/IsGreatestFontOnPageFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class IsGreatestFontOnPageFeature extends AbstractFeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone object, BxPage context) {
FeatureCalculator<BxZone, BxPage> fc = new FontHeightMeanFeature();
for (BxZone otherZone : getOtherZones(object)) {
if (fc.calculateFeatureValue(otherZone, context) > fc.calculateFeatureValue(object, context)) {
return 0.0;
}
}
return 1.0;
}
}
| 1,513 | 35.926829 | 107 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/WidthFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class WidthFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
return zone.getBounds().getWidth();
}
}
| 1,243 | 33.555556 | 78 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/WhitespaceCountFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class WhitespaceCountFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
int spaceCount = 0;
for (char c : zone.toText().toCharArray()) {
if (Character.isWhitespace(c)) {
++spaceCount;
}
}
return spaceCount;
}
}
| 1,388 | 33.725 | 79 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/IsLastPageFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class IsLastPageFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
return page.getNext() == null ? 1.0 : 0.0;
}
}
| 1,227 | 35.117647 | 78 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/IsLastButOnePageFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class IsLastButOnePageFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
if (page.getNext() != null && page.getNext().getNext() == null) {
return 1.0;
}
return 0.0;
}
}
| 1,311 | 33.526316 | 80 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/BibinfoFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import java.util.Locale;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class BibinfoFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
String[] keywords = {"cite", "pages", "article", "volume", "publishing", "journal", "doi", "cite this article",
"citation", "issue", "issn"};
String[] otherKeywords = {"author details", "university", "department", "school", "institute", "affiliation",
"hospital", "laboratory", "faculty", "author", "abstract", "keywords", "key words",
"correspondence", "editor", "address", "email"};
int count = 0;
for (String keyword : keywords) {
if (zone.toText().toLowerCase(Locale.ENGLISH).contains(keyword)) {
count += 2;
}
}
for (String keyword : otherKeywords) {
if (count > 0 && zone.toText().toLowerCase(Locale.ENGLISH).contains(keyword)) {
count--;
}
}
return (double)count / 2;
}
}
| 2,146 | 36.017241 | 119 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/AbstractFeatureCalculator.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import java.util.ArrayList;
import java.util.List;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
* @param <S> object class
* @param <T> context class
*/
public abstract class AbstractFeatureCalculator<S, T> extends FeatureCalculator<S, T> {
protected static List<BxPage> getOtherPages(BxPage page) {
List<BxPage> pages = new ArrayList<BxPage>();
BxPage prevPage = page.getPrev();
BxPage nextPage = page.getNext();
while (prevPage != null) {
pages.add(0, prevPage);
prevPage = prevPage.getPrev();
}
while (nextPage != null) {
pages.add(nextPage);
nextPage = nextPage.getNext();
}
return pages;
}
protected static List<BxZone> getOtherZones(BxZone zone) {
List<BxZone> zones = new ArrayList<BxZone>();
BxZone prevZone = zone.getPrev();
BxZone nextZone = zone.getNext();
while (prevZone != null) {
zones.add(0, prevZone);
prevZone = prevZone.getPrev();
}
while (nextZone != null) {
zones.add(nextZone);
nextZone = nextZone.getNext();
}
return zones;
}
}
| 2,159 | 31.727273 | 87 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/IsWidestOnThePageFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class IsWidestOnThePageFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone object, BxPage context) {
for (BxZone zone : context) {
if (zone.getWidth() > object.getWidth()) {
return 0.0;
}
}
return 1.0;
}
}
| 1,354 | 32.875 | 81 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/ContainsPageNumberFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import java.util.regex.Pattern;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class ContainsPageNumberFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
if (zone.childrenCount() > 1) {
return 0;
}
if (Pattern.matches("^\\d+$|^Page\\s+.*$|^page\\s+.*$", zone.toText())) {
return 1;
}
return 0;
}
}
| 1,448 | 32.697674 | 82 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/XPositionFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class XPositionFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
return zone.getBounds().getX();
}
}
| 1,243 | 33.555556 | 78 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/AbstractFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import java.util.Locale;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class AbstractFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
String[] keywords = {"abstract", "keywords", "key words"};
for (String keyword : keywords) {
if (zone.toText().toLowerCase(Locale.ENGLISH).startsWith(keyword)) {
return 1;
}
}
return 0;
}
}
| 1,486 | 32.795455 | 80 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/WidthRelativeFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class WidthRelativeFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
if (page.getBounds().getWidth() < 0.00001) {
return 0.0;
}
return zone.getBounds().getWidth() / page.getBounds().getWidth();
}
}
| 1,356 | 33.794872 | 78 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/LineXWidthPositionDiffFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxLine;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class LineXWidthPositionDiffFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
double min = zone.getBounds().getX() + zone.getBounds().getWidth();
double max = zone.getBounds().getX();
for (BxLine line : zone) {
if (line.getBounds().getX()+line.getBounds().getWidth() < min) {
min = line.getBounds().getX()+line.getBounds().getWidth();
}
if (line.getBounds().getX()+line.getBounds().getWidth() > max) {
max = line.getBounds().getX()+line.getBounds().getWidth();
}
}
return max - min;
}
}
| 1,791 | 37.12766 | 86 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/FontHeightMeanFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.*;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class FontHeightMeanFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
double heightSum = 0.0;
int heightNumber = 0;
for (BxLine line : zone) {
for (BxWord word : line) {
for (BxChunk chunk : word) {
heightSum += chunk.getBounds().getHeight();
++heightNumber;
}
}
}
return heightSum / heightNumber;
}
}
| 1,490 | 32.886364 | 78 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/LastButOneZoneFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
/**
* @author Pawel Szostek
*/
public class LastButOneZoneFeature extends AbstractFeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone object, BxPage context) {
if (object.hasPrev() && object.getPrev().hasPrev()) {
return (double) object.getPrev().getPrev().getLabel().ordinal();
}
return -1.0;
}
}
| 1,289 | 34.833333 | 86 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/GreekLettersFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class GreekLettersFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
return (zone.toText().matches("^.*[\\u0391-\\u03A9].*$") ||
zone.toText().matches("^.*[\\u03B1-\\u03C9].*$")) ? 1: 0;
}
}
| 1,352 | 35.567568 | 78 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/IsRightFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
/**
* @author Pawel Szostek
*/
public class IsRightFeature extends AbstractFeatureCalculator<BxZone, BxPage> {
private static final double TRESHOLD = 0.3;
@Override
public double calculateFeatureValue(BxZone object, BxPage context) {
if (object.getX() + object.getWidth() / 2.0 > context.getWidth() * (1 - TRESHOLD)) {
return 1.0;
} else {
return 0.0;
}
}
}
| 1,330 | 32.275 | 92 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/CharCountRelativeFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.*;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class CharCountRelativeFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
int count = 0;
for (BxLine line : zone) {
for (BxWord word : line) {
for (BxChunk chunk : word) {
count += chunk.toText().length();
}
}
}
int pCount = 0;
for (BxZone pZone : page) {
for (BxLine line : pZone) {
for (BxWord word : line) {
for (BxChunk chunk : word) {
pCount += chunk.toText().length();
}
}
}
}
return (double) count / (double) pCount;
}
}
| 1,758 | 32.188679 | 81 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/EmptySpaceRelativeFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class EmptySpaceRelativeFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
FeatureCalculator<BxZone, BxPage> emptySpaceCalc = new EmptySpaceFeature();
if (zone.getArea() < 0.0005) {
return 0.0;
} else {
double emptySpace = emptySpaceCalc.calculateFeatureValue(zone, page);
return emptySpace / zone.getArea();
}
}
}
| 1,488 | 36.225 | 83 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/FigureTableFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import java.util.Locale;
import pl.edu.icm.cermine.structure.model.*;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class FigureTableFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
int i = 0;
for (BxLine line : zone) {
String text = line.toText().toLowerCase(Locale.ENGLISH);
if (text.matches("figure ?[0-9ivx]+[\\.:].*$") || text.matches("table ?[0-9ivx]+[\\.:].*$")
|| text.matches("figure ?[0-9ivx]+$") || text.matches("table ?[0-9ivx]+$")) {
if (i == 0) {
return 1;
}
if (Math.abs(line.getX() - line.getPrev().getX()) > 5) {
return 1;
}
double prevW = 0;
for (BxWord w : line.getPrev()) {
for (BxChunk ch : w) {
prevW += ch.getArea();
}
}
prevW /= Math.max(line.getPrev().getArea(), line.getArea());
double lineW = 0;
for (BxWord w : line) {
for (BxChunk ch : w) {
prevW += ch.getArea();
}
}
lineW /= Math.max(line.getPrev().getArea(), line.getArea());
if (Math.abs(lineW -prevW) < 0.3) {
return 1;
}
return 0.3;
}
i++;
}
return 0;
}
}
| 2,462 | 35.220588 | 103 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/IsFontBiggerThanNeighboursFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import com.google.common.collect.Lists;
import java.util.List;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Pawel Szostek
*/
public class IsFontBiggerThanNeighboursFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
List<BxZone> pageZones = Lists.newArrayList(page);
if (pageZones.isEmpty()) {
return 0.0;
}
if (pageZones.size() == 1) {
return 1.0;
}
Integer thisZoneIdx = null;
for (int zoneIdx = 0; zoneIdx < pageZones.size(); ++zoneIdx) {
if (zone == pageZones.get(zoneIdx)) {
thisZoneIdx = zoneIdx;
break;
}
}
assert thisZoneIdx != null : "No zone in zone's context found";
if (thisZoneIdx == 0) {
FeatureCalculator<BxZone, BxPage> fontHeight = new FontHeightMeanFeature();
double nextZoneFont = fontHeight.calculateFeatureValue(
pageZones.get(thisZoneIdx + 1), page);
double thisZoneFont = fontHeight.calculateFeatureValue(
pageZones.get(thisZoneIdx), page);
return thisZoneFont > nextZoneFont ? 1.0 : 0.0;
} else if (thisZoneIdx == pageZones.size() - 1) {
FeatureCalculator<BxZone, BxPage> fontHeight = new FontHeightMeanFeature();
double prevZoneFont = fontHeight.calculateFeatureValue(
pageZones.get(thisZoneIdx - 1), page);
double thisZoneFont = fontHeight.calculateFeatureValue(
pageZones.get(thisZoneIdx), page);
return thisZoneFont > prevZoneFont ? 1.0 : 0.0;
} else {
FeatureCalculator<BxZone, BxPage> fontHeight = new FontHeightMeanFeature();
double prevZoneFont = fontHeight.calculateFeatureValue(
pageZones.get(thisZoneIdx - 1), page);
double thisZoneFont = fontHeight.calculateFeatureValue(
pageZones.get(thisZoneIdx), page);
double nextZoneFont = fontHeight.calculateFeatureValue(
pageZones.get(thisZoneIdx + 1), page);
return (thisZoneFont > prevZoneFont && thisZoneFont > nextZoneFont) ? 1.0
: 0.0;
}
}
}
| 3,263 | 40.846154 | 90 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/IsAfterMetTitleFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
/**
* @author Pawel Szostek
*/
public class IsAfterMetTitleFeature extends AbstractFeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone object, BxPage context) {
if (object.getPrev() == null || object.getPrev().getLabel() != BxZoneLabel.MET_TITLE) {
return 0.0;
}
return 1.0;
}
}
| 1,326 | 33.921053 | 95 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/LineXPositionMeanFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxLine;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class LineXPositionMeanFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
double mean = 0;
for (BxLine line : zone) {
mean += line.getBounds().getX();
}
return mean / (double) zone.childrenCount() - zone.getBounds().getX();
}
}
| 1,455 | 34.512195 | 81 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/LineXPositionDiffFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.BxLine;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class LineXPositionDiffFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
double min = zone.getBounds().getX() + zone.getBounds().getWidth();
double max = zone.getBounds().getX();
for (BxLine line : zone) {
if (line.getBounds().getX() < min) {
min = line.getBounds().getX();
}
if (line.getBounds().getX() > max) {
max = line.getBounds().getX();
}
}
return max - min;
}
}
| 1,674 | 34.638298 | 81 | java |
CERMINE | CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/zoneclassification/features/DigitRelativeCountFeature.java | /**
* This file is part of CERMINE project.
* Copyright (c) 2011-2018 ICM-UW
*
* CERMINE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CERMINE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.edu.icm.cermine.metadata.zoneclassification.features;
import pl.edu.icm.cermine.structure.model.*;
import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator;
/**
* @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
*/
public class DigitRelativeCountFeature extends FeatureCalculator<BxZone, BxPage> {
@Override
public double calculateFeatureValue(BxZone zone, BxPage page) {
int count = 0;
int allCount = 0;
for (BxLine line : zone) {
for (BxWord word : line) {
for (BxChunk chunk : word) {
char[] arr = chunk.toText().toCharArray();
for (int i = 0; i < arr.length; i++) {
allCount++;
if (Character.isDigit(arr[i])) {
count++;
}
}
}
}
}
return (double) count / (double) allCount;
}
}
| 1,717 | 34.061224 | 82 | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.