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/content/headers/features/IsCapitalizedSingleWordFeature.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.content.headers.features; import pl.edu.icm.cermine.structure.model.BxLine; import pl.edu.icm.cermine.structure.model.BxPage; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsCapitalizedSingleWordFeature extends FeatureCalculator<BxLine, BxPage> { @Override public double calculateFeatureValue(BxLine line, BxPage context) { return (line.toText().matches("^[A-Z][a-z]*$") ? 1 : 0); } }
1,273
34.388889
87
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/content/citations/CitationPositionFinder.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.content.citations; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; import pl.edu.icm.cermine.bibref.model.BibEntry; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.bibref.parsing.tools.CitationUtils; import pl.edu.icm.cermine.tools.CharacterUtils; import pl.edu.icm.cermine.tools.TextUtils; /** * A class for extracting citation positions from the document's full text. * * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class CitationPositionFinder { public List<Set<CitationPosition>> findReferences(String fullText, List<BibEntry> citations) { DocumentPositions docPositions = new DocumentPositions(fullText.length(), citations); for (BibEntry citation: citations) { findByNumber(fullText, citation, "\\[", "\\]", docPositions); } List<Set<CitationPosition>> positionsBySquare = docPositions.getPositions(); docPositions = new DocumentPositions(fullText.length(), citations); for (BibEntry citation: citations) { findByAuthorYear(fullText, citation, docPositions); if (docPositions.getPositions(citation).isEmpty()) { findByAuthorYearFuzzy(fullText, citation, docPositions); } } List<Set<CitationPosition>> positionsByAuthor = docPositions.getPositions(); docPositions = new DocumentPositions(fullText.length(), citations); for (BibEntry citation: citations) { findByNumber(fullText, citation, "\\(", "\\)", docPositions); } List<Set<CitationPosition>> positionsByRound = docPositions.getPositions(); List<Set<CitationPosition>> positions = positionsByAuthor; if (sumOfSizes(positionsBySquare) > sumOfSizes(positions)) { positions = positionsBySquare; } if (sumOfSizes(positionsByRound) > sumOfSizes(positions)) { positions = positionsByRound; } return positions; } private void findByAuthorYear(String fullText, BibEntry citation, DocumentPositions positions) { List<String> tokens = new ArrayList<String>(); for (CitationToken token : CitationUtils.stringToCitation(citation.getText()).getTokens()) { tokens.add(token.getText().toLowerCase(Locale.ENGLISH).trim()); } Pattern refPattern = Pattern.compile("\\([^\\(\\)]+\\d{4}[^\\(\\)]*\\)"); Matcher refMatcher = refPattern.matcher(fullText); while (refMatcher.find()) { String reference = refMatcher.group().toLowerCase(Locale.ENGLISH).replaceAll("^.", "").replaceAll(".$", ""); String[] refs = reference.split(";"); for (String ref : refs) { Pattern namePattern = Pattern.compile("[a-z]{2,}"); Matcher nameMatcher = namePattern.matcher(ref); Pattern yearPattern = Pattern.compile("\\d{4}"); Matcher yearMatcher = yearPattern.matcher(ref); boolean nameFound = false; boolean yearFound = false; while (nameMatcher.find()){ String name = nameMatcher.group(); if (tokens.contains(name) && tokens.indexOf(name) < 10) { nameFound = true; } } while (yearMatcher.find()) { String year = yearMatcher.group(); if (citation.getText().contains(year)) { yearFound = true; } } if (nameFound && yearFound) { positions.addPosition(citation, refMatcher.start(), refMatcher.end()); } } } refPattern = Pattern.compile("([A-Z][^\\s\\.]+)\\s+et\\s+al\\.\\s+\\((\\d{4})\\)"); refMatcher = refPattern.matcher(fullText); while (refMatcher.find()) { String year = refMatcher.group(2); if (!TextUtils.isNumberBetween(year, 1700, 2100) || !citation.getText().contains(year)) { continue; } if (citation.getText().startsWith(refMatcher.group(1))) { positions.addPosition(citation, refMatcher.start(), refMatcher.end()); } } refPattern = Pattern.compile("([A-Z][^\\s\\.]+)\\s+(and|&)\\s+[A-Z][^\\s\\.]+\\s+\\((\\d{4})\\)"); refMatcher = refPattern.matcher(fullText); while (refMatcher.find()) { String year = refMatcher.group(3); if (!TextUtils.isNumberBetween(year, 1700, 2100) || !citation.getText().contains(year)) { continue; } if (citation.getText().startsWith(refMatcher.group(1))) { positions.addPosition(citation, refMatcher.start(), refMatcher.end()); } } refPattern = Pattern.compile("([A-Z][^\\s\\.]+)\\s+\\((\\d{4})\\)"); refMatcher = refPattern.matcher(fullText); while (refMatcher.find()) { String year = refMatcher.group(2); if (!TextUtils.isNumberBetween(year, 1700, 2100) || !citation.getText().contains(year)) { continue; } if (citation.getText().startsWith(refMatcher.group(1))) { positions.addPosition(citation, refMatcher.start(), refMatcher.end()); } } } private void findByAuthorYearFuzzy(String fullText, BibEntry citation, DocumentPositions positions) { Pattern namePattern = Pattern.compile("^\\w+"); Matcher nameMatcher = namePattern.matcher(citation.getText()); if (nameMatcher.find()) { String name = nameMatcher.group(); Pattern refPattern = Pattern.compile(name + "\\D{1,30}(\\d{4})", Pattern.CASE_INSENSITIVE); Matcher refMatcher = refPattern.matcher(fullText); while (refMatcher.find()) { String year = refMatcher.group(1); if (!TextUtils.isNumberBetween(year, 1700, 2100) || !citation.getText().contains(year)) { continue; } positions.addPosition(citation, refMatcher.start(), refMatcher.end()); } } } private void findByNumber(String fullText, BibEntry citation, String leftBracket, String rightBracket, DocumentPositions positions) { Pattern numberPattern = Pattern.compile("^[^\\d]{0,10}(\\d{1,5})"); Matcher numberMatcher = numberPattern.matcher(citation.getText()); String number; if (numberMatcher.find()) { number = numberMatcher.group(1); } else { return; } Pattern refPattern = Pattern.compile(leftBracket + "([,\\s\\d" + String.valueOf(CharacterUtils.DASH_CHARS) + "]+)" + rightBracket); Matcher refMatcher = refPattern.matcher(fullText); while (refMatcher.find()) { String[] matched = refMatcher.group(1).replaceAll("\\s", "").split(","); for (String match : matched) { if (number.equals(match)) { positions.addPosition(citation, refMatcher.start(1), refMatcher.end(1)); } else { Pattern rangePattern = Pattern.compile("^(\\d{1,5})[" + String.valueOf(CharacterUtils.DASH_CHARS) + "](\\d{1,5})$"); Matcher rangeMatcher = rangePattern.matcher(match); if (rangeMatcher.find()) { try { int lower = Integer.parseInt(rangeMatcher.group(1)); int upper = Integer.parseInt(rangeMatcher.group(2)); if (TextUtils.isNumberBetween(number, lower, upper+1)) { positions.addPosition(citation, refMatcher.start(1), refMatcher.end(1)); } } catch (NumberFormatException e) {} } } } } } private int sumOfSizes(List<Set<CitationPosition>> positions) { int sum = 0; for (Set<CitationPosition> pos : positions) { sum += pos.size(); } return sum; } private static class DocumentPositions { private final boolean[] covered; List<CitationPosition> positions = new ArrayList<CitationPosition>(); List<BibEntry> citations; Map<BibEntry, Set<CitationPosition>> citationPositions = new HashMap<BibEntry, Set<CitationPosition>>(); public DocumentPositions(int size, List<BibEntry> citations) { covered = new boolean[size]; this.citations = citations; positions = new ArrayList<CitationPosition>(); citationPositions = new HashMap<BibEntry, Set<CitationPosition>>(); for (BibEntry citation : citations) { citationPositions.put(citation, new HashSet<CitationPosition>()); } } private void addPosition(BibEntry citation, int start, int end) { boolean exists = false; for (int i = start; i < end; i++) { if (covered[i]) { exists = true; } } if (exists) { for (CitationPosition pos : positions) { if (start == pos.getStartRefPosition() && end == pos.getEndRefPosition()) { exists = false; } } } if (!exists) { CitationPosition position = new CitationPosition(); position.setStartRefPosition(start); position.setEndRefPosition(end); positions.add(position); citationPositions.get(citation).add(position); for (int i = start; i < end; i++) { covered[i] = true; } } } private List<Set<CitationPosition>> getPositions() { List<Set<CitationPosition>> ret = new ArrayList<Set<CitationPosition>>(); for (BibEntry citation : citations) { ret.add(citationPositions.get(citation)); } return ret; } private Set<CitationPosition> getPositions(BibEntry citation) { return citationPositions.get(citation); } } }
11,460
41.925094
139
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/content/citations/ContentCitationPositionFinder.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.content.citations; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import pl.edu.icm.cermine.bibref.model.BibEntry; import pl.edu.icm.cermine.content.model.ContentStructure; import pl.edu.icm.cermine.content.model.DocumentSection; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class ContentCitationPositionFinder { public ContentStructureCitationPositions findReferences(ContentStructure structure, List<BibEntry> citations) { List<Integer> indexes = new ArrayList<Integer>(); Map<Integer, Integer> paragraphIndex = new HashMap<Integer, Integer>(); Map<Integer, DocumentSection> sectionIndex = new HashMap<Integer, DocumentSection>(); List<DocumentSection> sections = toSectionList(structure); StringBuilder sb = new StringBuilder(); int length = 0; int index = 0; for (DocumentSection section : sections) { for (int i = 0; i < section.getParagraphs().size(); i++) { indexes.add(length); paragraphIndex.put(index, i); sectionIndex.put(index, section); sb.append(section.getParagraphs().get(i)); length += section.getParagraphs().get(i).length(); index++; } } String fullText = sb.toString(); CitationPositionFinder finder = new CitationPositionFinder(); List<Set<CitationPosition>> positions = finder.findReferences(fullText, citations); ContentStructureCitationPositions contentPositions = new ContentStructureCitationPositions(); for (int i = 0; i < positions.size(); i++) { Set<CitationPosition> citationPositions = positions.get(i); for (CitationPosition pos : citationPositions) { int start = findIndex(pos.getStartRefPosition(), indexes); int end = findIndex(pos.getEndRefPosition(), indexes); if (start != end) { continue; } CitationPosition shifted = new CitationPosition(); shifted.setStartRefPosition(pos.getStartRefPosition()-indexes.get(start)); shifted.setEndRefPosition(pos.getEndRefPosition()-indexes.get(start)); contentPositions.addPosition(sectionIndex.get(start), paragraphIndex.get(start), i, shifted); } } return contentPositions; } private int findIndex(int i, List<Integer> indexes) { int prev = -1; for (int index : indexes) { if (index > i) { return prev; } prev++; } return prev; } private List<DocumentSection> toSectionList(ContentStructure structure) { List<DocumentSection> sections = new ArrayList<DocumentSection>(); for (DocumentSection section : structure.getSections()) { addSections(sections, section); } return sections; } private void addSections(List<DocumentSection> sectionList, DocumentSection section) { sectionList.add(section); for (DocumentSection subsection : section.getSubsections()) { addSections(sectionList, subsection); } } }
4,107
38.12381
115
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/content/citations/CitationPosition.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.content.citations; /** * A class for storing the position of a single reference to another document in a document's text. * * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class CitationPosition { private int startRefPosition; private int endRefPosition; /** * Returns the index of the character following the last reference character * in the document's text. * * @return the index of the character */ public int getEndRefPosition() { return endRefPosition; } public void setEndRefPosition(int endRefPosition) { this.endRefPosition = endRefPosition; } /** * Returns the index of the first reference character in the document's text. * * @return the index of the first reference character */ public int getStartRefPosition() { return startRefPosition; } public void setStartRefPosition(int startRefPosition) { this.startRefPosition = startRefPosition; } @Override public int hashCode() { int hash = 3; hash = 47 * hash + this.startRefPosition; hash = 47 * hash + this.endRefPosition; return hash; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final CitationPosition other = (CitationPosition) obj; return this.startRefPosition == other.startRefPosition && this.endRefPosition == other.endRefPosition; } }
2,431
27.27907
99
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/content/citations/ContentStructureCitationPositions.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.content.citations; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import pl.edu.icm.cermine.content.model.DocumentSection; import pl.edu.icm.cermine.tools.Pair; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class ContentStructureCitationPositions { private final Map<DocumentSection, Map<String, List<CitationPosition>>> positions = new HashMap<DocumentSection, Map<String, List<CitationPosition>>>(); void addPosition(DocumentSection section, int paragraphIndex, int citationIndex, CitationPosition position) { if (positions.get(section) == null) { positions.put(section, new HashMap<String, List<CitationPosition>>()); } String index = String.valueOf(paragraphIndex) + " " + String.valueOf(citationIndex); if (positions.get(section).get(index) == null) { positions.get(section).put(index, new ArrayList<CitationPosition>()); } positions.get(section).get(index).add(position); } public List<Pair<Integer, CitationPosition>> getPositions(DocumentSection section, int index) { List<Pair<Integer, CitationPosition>> ret = new ArrayList<Pair<Integer, CitationPosition>>(); Map<String, List<CitationPosition>> map = positions.get(section); if (map == null) { return ret; } for (Entry<String, List<CitationPosition>> entry : map.entrySet()) { int paragraphIndex = Integer.parseInt(entry.getKey().split(" ")[0]); int citationIndex = Integer.parseInt(entry.getKey().split(" ")[1]); if (paragraphIndex == index) { for (CitationPosition p : entry.getValue()) { ret.add(new Pair<Integer, CitationPosition>(citationIndex, p)); } } } return ret; } }
2,684
39.074627
113
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/content/filtering/SVMContentFilter.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.content.filtering; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.logging.Level; import java.util.logging.Logger; import pl.edu.icm.cermine.exception.AnalysisException; import pl.edu.icm.cermine.structure.model.*; import pl.edu.icm.cermine.tools.classification.general.FeatureVectorBuilder; import pl.edu.icm.cermine.tools.classification.svm.SVMClassifier; import pl.edu.icm.cermine.tools.timeout.TimeoutRegister; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class SVMContentFilter extends SVMClassifier<BxZone, BxPage, BxZoneLabel> implements ContentFilter { public SVMContentFilter(BufferedReader modelFile, BufferedReader rangeFile) throws AnalysisException { this(modelFile, rangeFile, ContentFilterTools.VECTOR_BUILDER); } public SVMContentFilter(String modelFilePath, String rangeFilePath) throws AnalysisException { this(modelFilePath, rangeFilePath, ContentFilterTools.VECTOR_BUILDER); } public SVMContentFilter(BufferedReader modelFile, BufferedReader rangeFile, FeatureVectorBuilder<BxZone, BxPage> featureVectorBuilder) throws AnalysisException { super(featureVectorBuilder, BxZoneLabel.class); try { loadModelFromFile(modelFile, rangeFile); } catch (IOException ex) { throw new AnalysisException("Cannot create SVM classifier!", ex); } } public SVMContentFilter(String modelFilePath, String rangeFilePath, FeatureVectorBuilder<BxZone, BxPage> featureVectorBuilder) throws AnalysisException { super(featureVectorBuilder, BxZoneLabel.class); InputStreamReader modelISR = null; try { modelISR = new InputStreamReader(SVMContentFilter.class .getResourceAsStream(modelFilePath), "UTF-8"); BufferedReader modelFile = new BufferedReader(modelISR); InputStreamReader rangeISR = new InputStreamReader(SVMContentFilter.class .getResourceAsStream(rangeFilePath), "UTF-8"); BufferedReader rangeFile = new BufferedReader(rangeISR); loadModelFromFile(modelFile, rangeFile); } catch (IOException ex) { throw new AnalysisException("Cannot create SVM classifier!", ex); } finally { try { if (modelISR != null) { modelISR.close(); } } catch (IOException ex) { Logger.getLogger(SVMContentFilter.class.getName()).log(Level.SEVERE, null, ex); } } } @Override public BxDocument filter(BxDocument document) throws AnalysisException { for (BxZone zone : document.asZones()) { if (zone.getLabel().isOfCategoryOrGeneral(BxZoneLabelCategory.CAT_BODY)) { zone.setLabel(predictLabel(zone, zone.getParent())); } TimeoutRegister.get().check(); } return document; } }
3,775
40.955556
165
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/content/filtering/ContentFilter.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.content.filtering; import pl.edu.icm.cermine.exception.AnalysisException; import pl.edu.icm.cermine.structure.model.BxDocument; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public interface ContentFilter { BxDocument filter(BxDocument document) throws AnalysisException; }
1,063
32.25
78
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/content/filtering/ContentFilterTools.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.content.filtering; import java.util.Arrays; import 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; import pl.edu.icm.cermine.tools.classification.general.FeatureVectorBuilder; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public final class ContentFilterTools { public static final FeatureVectorBuilder<BxZone, BxPage> VECTOR_BUILDER = new FeatureVectorBuilder<BxZone, BxPage>(); static { VECTOR_BUILDER.setFeatureCalculators(Arrays.<FeatureCalculator<BxZone, BxPage>>asList( new FigureFeature(), new IsLastPageFeature(), new AcknowledgementFeature(), new AuthorFeature(), new IsWidestOnThePageFeature(), new LicenseFeature(), new BracketedLineRelativeCountFeature(), new ContainsPageNumberFeature(), new IsLeftFeature(), new IsAnywhereElseFeature(), new FigureTableFeature(), new AffiliationFeature(), new IsLowestOnThePageFeature(), new IsOnSurroundingPagesFeature(), new BibinfoFeature(), new IsFirstPageFeature(), new IsLongestOnThePageFeature(), new IsFontBiggerThanNeighboursFeature(), new YearFeature(), new ContainsCuePhrasesFeature(), new CuePhrasesRelativeCountFeature(), new DigitCountFeature(), new IsSingleWordFeature(), new ReferencesFeature(), new BracketCountFeature(), new BracketRelativeCountFeature(), new PageNumberFeature(), new DotCountFeature(), new StartsWithDigitFeature(), new AuthorNameRelativeFeature(), new LineCountFeature(), new LineHeightMaxMeanFeature(), new LineXPositionDiffFeature(), new LineXPositionMeanFeature(), new CommaCountFeature(), new UppercaseWordCountFeature(), new UppercaseCountFeature(), new XVarianceFeature(), new CommaRelativeCountFeature(), new UppercaseWordRelativeCountFeature(), new DotRelativeCountFeature(), new FullWordsRelativeFeature(), new DigitRelativeCountFeature(), new LowercaseCountFeature(), new WordLengthMeanFeature(), new LineXWidthPositionDiffFeature(), new UppercaseRelativeCountFeature(), new PunctuationRelativeCountFeature(), new LastButOneZoneFeature(), new LineRelativeCountFeature(), new PreviousZoneFeature(), new LineHeightMeanFeature(), new XPositionFeature(), new HorizontalRelativeProminenceFeature(), new DistanceFromNearestNeighbourFeature(), new EmptySpaceFeature(), new EmptySpaceRelativeFeature(), new VerticalProminenceFeature(), new YPositionFeature(), new YPositionRelativeFeature(), new LineWidthMeanFeature(), new ProportionsFeature(), new RelativeMeanLengthFeature() )); } private ContentFilterTools() { } }
4,172
38.367925
121
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/BibReferenceParser.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.bibref; import pl.edu.icm.cermine.exception.AnalysisException; /** * Bibliographic reference parser. * * @author Lukasz Bolikowski (bolo@icm.edu.pl) * * @param <T> Type of parsed reference. */ public interface BibReferenceParser<T> { /** * Parses a text of a reference. * * @param text text * @return Parsed reference, or <code>null</code> if the specified text * couldn't be parsed. * @throws AnalysisException AnalysisException */ T parseBibReference(String text) throws AnalysisException; }
1,310
30.214286
78
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/CRFBibReferenceParser.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.bibref; import edu.umass.cs.mallet.base.pipe.Pipe; import edu.umass.cs.mallet.base.pipe.iterator.LineGroupIterator; import edu.umass.cs.mallet.base.types.InstanceList; import edu.umass.cs.mallet.base.types.LabelsSequence; import edu.umass.cs.mallet.grmm.learning.ACRF; import java.io.*; import java.util.HashSet; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; import org.apache.commons.cli.*; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.jdom.Element; import org.jdom.output.Format; import org.jdom.output.XMLOutputter; import pl.edu.icm.cermine.bibref.model.BibEntry; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationTokenLabel; import pl.edu.icm.cermine.bibref.parsing.tools.CitationUtils; import pl.edu.icm.cermine.bibref.transformers.BibEntryToNLMConverter; import pl.edu.icm.cermine.configuration.ExtractionConfigBuilder; import pl.edu.icm.cermine.configuration.ExtractionConfigProperty; import pl.edu.icm.cermine.configuration.ExtractionConfigRegister; import pl.edu.icm.cermine.exception.AnalysisException; import pl.edu.icm.cermine.exception.TransformationException; import pl.edu.icm.cermine.tools.PrefixTree; import pl.edu.icm.cermine.tools.ResourceUtils; /** * CRF-based bibiliographic reference parser. * * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class CRFBibReferenceParser implements BibReferenceParser<BibEntry> { private static final int MAX_REFERENCE_LENGTH = 3000; private ACRF model; private Set<String> terms; private Set<String> journals; private Set<String> surnames; private Set<String> insts; public CRFBibReferenceParser(String modelFile, String termsFile, String journalsFile, String surnamesFile, String instsFile) throws AnalysisException { InputStream modelIS; InputStream termsIS; InputStream journalsIS; InputStream surnamesIS; InputStream instsIS; try { modelIS = ResourceUtils.openResourceStream(modelFile); termsIS = ResourceUtils.openResourceStream(termsFile); journalsIS = ResourceUtils.openResourceStream(journalsFile); surnamesIS = ResourceUtils.openResourceStream(surnamesFile); instsIS = ResourceUtils.openResourceStream(instsFile); loadModels(modelIS, termsIS, journalsIS, surnamesIS, instsIS); } catch (IOException ex) { throw new AnalysisException("Cannot set model!", ex); } finally { } } public CRFBibReferenceParser(InputStream modelIS, InputStream termsIS, InputStream journalsIS, InputStream surnamesIS, InputStream instsIS) throws AnalysisException { loadModels(modelIS, termsIS, journalsIS, surnamesIS, instsIS); } public void loadModels(InputStream modelIS, InputStream termsIS, InputStream journalsIS, InputStream surnamesIS, InputStream instsIS) throws AnalysisException { // prevents MALLET from printing info messages System.setProperty("java.util.logging.config.file", "edu/umass/cs/mallet/base/util/resources/logging.properties"); ObjectInputStream ois = null; try { ois = new ObjectInputStream(new BufferedInputStream(new GZIPInputStream(modelIS))); model = (ACRF)(ois.readObject()); } catch (IOException ex) { throw new AnalysisException("Cannot set model!", ex); } catch (ClassNotFoundException ex) { throw new AnalysisException("Cannot set model!", ex); } finally { try { if (ois != null) { ois.close(); } } catch (IOException ex) { throw new AnalysisException("Cannot set model!", ex); } } terms = new HashSet<String>(); try { terms.addAll(IOUtils.readLines(termsIS, "UTF-8")); } catch (IOException ex) { Logger.getLogger(CRFBibReferenceParser.class.getName()).log(Level.SEVERE, "Cannot load common words!", ex); } journals = new HashSet<String>(); try { journals.addAll(IOUtils.readLines(journalsIS, "UTF-8")); } catch (IOException ex) { Logger.getLogger(CRFBibReferenceParser.class.getName()).log(Level.SEVERE, "Cannot load common journals!", ex); } surnames = new HashSet<String>(); try { surnames.addAll(IOUtils.readLines(surnamesIS, "UTF-8")); } catch (IOException ex) { Logger.getLogger(CRFBibReferenceParser.class.getName()).log(Level.SEVERE, "Cannot load common surnames!", ex); } insts = new HashSet<String>(); try { insts.addAll(IOUtils.readLines(instsIS, "UTF-8")); } catch (IOException ex) { Logger.getLogger(CRFBibReferenceParser.class.getName()).log(Level.SEVERE, "Cannot load common institutions!", ex); } } @Override public BibEntry parseBibReference(String text) throws AnalysisException { Citation citation = parseToTokenList(text); return CitationUtils.citationToBibref(citation); } public Citation parseToTokenList(String text) throws AnalysisException { if (model == null) { throw new AnalysisException("Model object is not set!"); } Citation citation = CitationUtils.stringToCitation(text); if (text.length() > MAX_REFERENCE_LENGTH) { return citation; } PrefixTree journalsPt = new PrefixTree(PrefixTree.START_TERM); journalsPt.build(journals); PrefixTree surnamesPt = new PrefixTree(PrefixTree.START_TERM); surnamesPt.build(surnames); PrefixTree instPt = new PrefixTree(PrefixTree.START_TERM); instPt.build(insts); String data = StringUtils.join(CitationUtils.citationToMalletInputFormat(citation, terms, journalsPt, surnamesPt, instPt), "\n"); Pipe pipe = model.getInputPipe(); InstanceList instanceList = new InstanceList(pipe); instanceList.add(new LineGroupIterator(new StringReader(data), Pattern.compile ("\\s*"), true)); if (model.getBestLabels(instanceList).isEmpty()) { return citation; } LabelsSequence labelSequence = (LabelsSequence)model.getBestLabels(instanceList).get(0); for (int i = 0; i < labelSequence.size(); i++) { CitationTokenLabel label = CitationTokenLabel.valueOf(labelSequence.get(i).toString()); if (CitationTokenLabel.getNormalizedLabel(label) != null) { label = CitationTokenLabel.getNormalizedLabel(label); } citation.getTokens().get(i).setLabel(label); } return citation; } public static CRFBibReferenceParser getInstance() throws AnalysisException { return new CRFBibReferenceParser(ExtractionConfigRegister.get().getStringProperty(ExtractionConfigProperty.BIBREF_MODEL_PATH), ExtractionConfigRegister.get().getStringProperty(ExtractionConfigProperty.BIBREF_TERMS_PATH), ExtractionConfigRegister.get().getStringProperty(ExtractionConfigProperty.BIBREF_JOURNALS_PATH), ExtractionConfigRegister.get().getStringProperty(ExtractionConfigProperty.BIBREF_SURNAMES_PATH), ExtractionConfigRegister.get().getStringProperty(ExtractionConfigProperty.BIBREF_INSTITUTIONS_PATH)); } public static void main(String[] args) throws ParseException, AnalysisException, TransformationException { Options options = new Options(); options.addOption("reference", true, "reference text"); options.addOption("format", true, "output format"); options.addOption("configuration", true, "config path"); CommandLineParser clParser = new DefaultParser(); CommandLine line = clParser.parse(options, args); String referenceText = line.getOptionValue("reference"); String outputFormat = line.getOptionValue("format"); ExtractionConfigBuilder builder = new ExtractionConfigBuilder(); if (line.hasOption("configuration")) { builder.addConfiguration(line.getOptionValue("configuration")); } ExtractionConfigRegister.set(builder.buildConfiguration()); if (referenceText == null || (outputFormat != null && !outputFormat.equals("bibtex") && !outputFormat.equals("nlm"))) { System.err.println("Usage: CRFBibReferenceParser -ref <reference text> [-format <output format>]\n\n" + "Tool for extracting metadata from reference strings.\n\n" + "Arguments:\n" + " -reference the text of the reference\n" + " -format (optional) the format of the output,\n" + " possible values: BIBTEX (default) and NLM"); System.exit(1); } CRFBibReferenceParser parser = CRFBibReferenceParser.getInstance(); BibEntry reference = parser.parseBibReference(referenceText); if (outputFormat == null || outputFormat.equals("bibtex")) { System.out.println(reference.toBibTeX()); } else { BibEntryToNLMConverter converter = new BibEntryToNLMConverter(); Element element = converter.convert(reference); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); System.out.println(outputter.outputString(element)); } } }
10,609
44.34188
170
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/KMeansBibReferenceExtractor.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.bibref; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import pl.edu.icm.cermine.bibref.extraction.features.*; import pl.edu.icm.cermine.bibref.extraction.model.BxDocumentBibReferences; import pl.edu.icm.cermine.bibref.extraction.tools.BibRefExtractionUtils; import pl.edu.icm.cermine.content.cleaning.ContentCleaner; import pl.edu.icm.cermine.exception.AnalysisException; import pl.edu.icm.cermine.structure.model.BxDocument; import pl.edu.icm.cermine.structure.model.BxLine; import pl.edu.icm.cermine.tools.CharacterUtils; import pl.edu.icm.cermine.tools.classification.clustering.KMeansWithInitialCentroids; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; import pl.edu.icm.cermine.tools.classification.general.FeatureVector; import pl.edu.icm.cermine.tools.classification.general.FeatureVectorBuilder; import pl.edu.icm.cermine.tools.distance.FeatureVectorDistanceMetric; import pl.edu.icm.cermine.tools.distance.FeatureVectorEuclideanMetric; /** * Clustering-based bibliographic reference extractor. * * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class KMeansBibReferenceExtractor implements BibReferenceExtractor { public static final int MAX_REF_LINES_COUNT = 10000; public static final int MAX_REFS_COUNT = 1000; public static final int MAX_REF_LENGTH = 1500; private static final FeatureVectorBuilder<BxLine, BxDocumentBibReferences> VECTOR_BUILDER = new FeatureVectorBuilder<BxLine, BxDocumentBibReferences>(); static { VECTOR_BUILDER.setFeatureCalculators(Arrays.<FeatureCalculator<BxLine, BxDocumentBibReferences>>asList( new PrevEndsWithDotFeature(), new PrevRelativeLengthFeature(), new RelativeStartTresholdFeature(), new SpaceBetweenLinesFeature(), new StartsWithNumberFeature() )); } /** * Extracts individual bibliographic references from the document. The references lines * are clustered based on feature vector computed for them. The cluster containing the first line * is then assumed to be the set of all first lines, which allows for splitting references blocks * into individual references. * * @param document document * @return an array of extracted references * @throws AnalysisException AnalysisException */ @Override public String[] extractBibReferences(BxDocument document) throws AnalysisException { BxDocumentBibReferences documentReferences = BibRefExtractionUtils.extractBibRefLines(document); documentReferences.limit(MAX_REF_LINES_COUNT); List<String> lines = new ArrayList<String>(); List<FeatureVector> instances = new ArrayList<FeatureVector>(); FeatureVectorDistanceMetric metric = new FeatureVectorEuclideanMetric(); FeatureVector farthestInstance = null; double farthestDistance = 0; for (BxLine line : documentReferences.getLines()) { lines.add(ContentCleaner.clean(line.toText())); FeatureVector featureVector = VECTOR_BUILDER.getFeatureVector(line, documentReferences); instances.add(featureVector); if (farthestInstance == null) { farthestInstance = instances.get(0); } double distance = metric.getDistance(instances.get(0), featureVector); if (distance > farthestDistance) { farthestInstance = featureVector; farthestDistance = distance; } } if (lines.size() <= 1 || farthestDistance < 0.001) { if (lines.size() > MAX_REFS_COUNT) { return new String[]{}; } else { return lines.toArray(new String[lines.size()]); } } KMeansWithInitialCentroids clusterer = new KMeansWithInitialCentroids(2); FeatureVector[] centroids = new FeatureVector[2]; centroids[0] = instances.get(0); centroids[1] = farthestInstance; clusterer.setCentroids(centroids); List<FeatureVector>[] clusters = clusterer.cluster(instances); int firstInstanceClusterNum = 0; if (clusters[1].contains(instances.get(0))) { firstInstanceClusterNum = 1; } List<String> references = new ArrayList<String>(); String actRef = ""; for (int i = 0; i < lines.size(); i++) { if (clusters[firstInstanceClusterNum].contains(instances.get(i))) { if (!actRef.isEmpty() && actRef.matches(".*[0-9].*") && actRef.matches(".*[a-zA-Z].*") && actRef.length() < MAX_REF_LENGTH) { references.add(actRef); } actRef = lines.get(i); } else { String hyphenList = String.valueOf(CharacterUtils.DASH_CHARS); hyphenList = hyphenList.replaceAll("-", "") + "-"; if (actRef.matches(".*[a-zA-Z]["+hyphenList+"]")) { actRef = actRef.substring(0, actRef.length()-1); } else { actRef += " "; } actRef += lines.get(i); } } if (!actRef.isEmpty() && actRef.matches(".*[0-9].*") && actRef.matches(".*[a-zA-Z].*") && actRef.length() < MAX_REF_LENGTH) { references.add(actRef); } if (references.size() > MAX_REFS_COUNT) { references.clear(); } return references.toArray(new String[references.size()]); } }
6,414
41.483444
111
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/BibReferenceExtractor.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.bibref; import pl.edu.icm.cermine.exception.AnalysisException; import pl.edu.icm.cermine.structure.model.BxDocument; /** * Interface for extracting individual references strings from zones labelled as REFERENCES. * * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public interface BibReferenceExtractor { /** * Extracts individual reference strings from the document. * * @param document document * @return extracted references * @throws AnalysisException AnalysisException */ String[] extractBibReferences(BxDocument document) throws AnalysisException; }
1,371
33.3
93
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/extraction/tools/BibRefExtractionUtils.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.bibref.extraction.tools; import java.util.ArrayList; import java.util.List; import pl.edu.icm.cermine.bibref.extraction.model.BibReferenceLineLabel; import pl.edu.icm.cermine.bibref.extraction.model.BxDocumentBibReferences; import pl.edu.icm.cermine.exception.AnalysisException; import pl.edu.icm.cermine.structure.model.*; /** * Bibliographic reference extraction utility class. * * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public final class BibRefExtractionUtils { private BibRefExtractionUtils() {} /** * Extracts lines and zones labeled as "references" from BxDocument. * * @param document A document * @return an object holding references' lines and zones * @throws AnalysisException AnalysisException */ public static BxDocumentBibReferences extractBibRefLines(BxDocument document) throws AnalysisException { BxDocumentBibReferences lines = new BxDocumentBibReferences(); for (BxPage page : document) { for (BxZone zone : page) { if (zone.getLabel().isOfCategoryOrGeneral(BxZoneLabelCategory.CAT_REFERENCES)) { lines.addZone(zone); } } } return lines; } /** * Extracts lines and zones labeled as "references" from BxDocument. * Extracted lines are tagged with labels according to the list of document's references. * * @param document A document * @param references A list of document's references * @return an object holding extracted zones and tagged lines * @throws AnalysisException AnalysisException */ public static BxDocumentBibReferences extractBibRefLines(BxDocument document, List<String> references) throws AnalysisException { BxDocumentBibReferences refLines = extractBibRefLines(document); List<BxLine> lines = refLines.getLines(); int lineIndex = 0; int citationIndex = 0; String actCitation = null; boolean first = true; while (lineIndex < lines.size() && citationIndex < references.size()) { BxLine line = lines.get(lineIndex); if (actCitation == null) { actCitation = references.get(citationIndex); } if (actCitation.equals(line.toText())) { if (first) { refLines.setLabel(line, BibReferenceLineLabel.BIBREF_START); } else { refLines.setLabel(line, BibReferenceLineLabel.BIBREF_END); } first = true; actCitation = null; lineIndex++; citationIndex++; } else if (actCitation.startsWith(line.toText())) { if (first) { refLines.setLabel(line, BibReferenceLineLabel.BIBREF_START); } else { refLines.setLabel(line, BibReferenceLineLabel.BIBREF_INNER); } first = false; actCitation = actCitation.substring(line.toText().length() + 1); lineIndex++; } else { refLines.setLabel(line, BibReferenceLineLabel.BLOCK_LABEL); lineIndex++; } } while (lineIndex < lines.size()) { BxLine line = lines.get(lineIndex); refLines.setLabel(line, BibReferenceLineLabel.BLOCK_LABEL); lineIndex++; } return refLines; } /** * Groups references' lines according to the list of line labels obtained from HMM service. * * @param docRefs Document's untagged reference lines * @param labels A list of line labels * @return A list of bibliographic references */ public static String[] groupLinesIntoBibRefs(BxDocumentBibReferences docRefs, List<BibReferenceLineLabel> labels) { List<String> references = new ArrayList<String>(); String actCitation = ""; for (int i = 0; i < docRefs.getLines().size(); i++) { String line = docRefs.getLines().get(i).toText(); BibReferenceLineLabel label = labels.get(i); if (label.equals(BibReferenceLineLabel.BLOCK_LABEL)) { continue; } if (label.equals(BibReferenceLineLabel.BIBREF_START)) { if (!actCitation.isEmpty()) { references.add(actCitation); } actCitation = ""; } else { actCitation += " "; } actCitation += line; } if (!actCitation.isEmpty()) { references.add(actCitation); } return references.toArray(new String[references.size()]); } }
5,525
35.84
133
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/extraction/features/StartsWithNumberOrUppercaseFeature.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.bibref.extraction.features; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import pl.edu.icm.cermine.bibref.extraction.model.BxDocumentBibReferences; import pl.edu.icm.cermine.structure.model.BxLine; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class StartsWithNumberOrUppercaseFeature extends FeatureCalculator<BxLine, BxDocumentBibReferences> { @Override public double calculateFeatureValue(BxLine refLine, BxDocumentBibReferences refs) { String text = refLine.toText(); List<BxLine> lines = refs.getLines(); String[] patterns = {"^(\\d+).*", "^\\[(\\d+)\\].*"}; for (String pText : patterns) { Pattern pattern = Pattern.compile(pText); Matcher matcher = pattern.matcher(text); if (!matcher.matches()) { continue; } int index = lines.indexOf(refLine); String objectMatch = matcher.group(1); String prevMatch = null; String nextMatch = null; for (int i = index - 1; i >= 0; i--) { BxLine line = lines.get(i); Matcher prevMatcher = pattern.matcher(line.toText()); if (prevMatcher.matches()) { prevMatch = prevMatcher.group(1); break; } } for (int i = index + 1; i < lines.size(); i++) { BxLine line = lines.get(i); Matcher nextMatcher = pattern.matcher(line.toText()); if (nextMatcher.matches()) { nextMatch = nextMatcher.group(1); break; } } if (prevMatch != null && objectMatch != null && Integer.parseInt(prevMatch) + 1 == Integer.parseInt(objectMatch)) { return 1; } if (nextMatch != null && objectMatch != null && Integer.parseInt(objectMatch) + 1 == Integer.parseInt(nextMatch)) { return 1; } } Pattern pattern = Pattern.compile("^([A-Z]+)\\W.*$"); Matcher matcher = pattern.matcher(text); if (!matcher.matches()) { return 0; } int total = 0; for (BxLine line : refs.getLines()) { Matcher lineMatcher = pattern.matcher(line.toText()); if (total == 0 && !lineMatcher.matches()) { return 0; } if (lineMatcher.matches()) { total++; } } return (total * 4 >= refs.getLines().size()) ? 1 : 0; } }
3,519
34.555556
108
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/extraction/features/StartsWithRefFeature.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.bibref.extraction.features; import pl.edu.icm.cermine.bibref.extraction.model.BxDocumentBibReferences; import pl.edu.icm.cermine.structure.model.BxLine; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class StartsWithRefFeature extends FeatureCalculator<BxLine, BxDocumentBibReferences> { @Override public double calculateFeatureValue(BxLine refLine, BxDocumentBibReferences refs) { String[] keywords = {"refe", "bibl"}; for (String keyword : keywords) { if (refLine.toText().startsWith(keyword)) { return 1; } } return 0; } }
1,476
33.348837
94
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/extraction/features/PrevRelativeLengthFeature.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.bibref.extraction.features; import pl.edu.icm.cermine.bibref.extraction.model.BxDocumentBibReferences; import pl.edu.icm.cermine.structure.model.BxLine; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class PrevRelativeLengthFeature extends FeatureCalculator<BxLine, BxDocumentBibReferences> { @Override public double calculateFeatureValue(BxLine refLine, BxDocumentBibReferences refs) { if (refs.getLines().indexOf(refLine) == 0) { return 0.2; } BxLine prev = refs.getLines().get(refs.getLines().indexOf(refLine)-1); return prev.getBounds().getWidth() / refs.getZone(prev).getBounds().getWidth(); } }
1,539
36.560976
99
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/extraction/features/StartsWithNumberFeature.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.bibref.extraction.features; import java.util.regex.Matcher; import java.util.regex.Pattern; import pl.edu.icm.cermine.bibref.extraction.model.BxDocumentBibReferences; import pl.edu.icm.cermine.structure.model.BxLine; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class StartsWithNumberFeature extends FeatureCalculator<BxLine, BxDocumentBibReferences> { @Override public double calculateFeatureValue(BxLine refLine, BxDocumentBibReferences refs) { String[] patterns = {"^\\[(\\d{1,3})\\] .*", "^(\\d{1,3})\\.? .*"}; for (String pText : patterns) { Pattern pattern = Pattern.compile(pText); Matcher matcher = pattern.matcher(refLine.toText()); if (!matcher.matches()) { continue; } int index = refs.getLines().indexOf(refLine); String objectMatch = matcher.group(1); String prevMatch = null; String nextMatch = null; for (int i = index - 1; i >= 0; i--) { BxLine line = refs.getLines().get(i); Matcher prevMatcher = pattern.matcher(line.toText()); if (prevMatcher.matches()) { prevMatch = prevMatcher.group(1); break; } } for (int i = index + 1; i < refs.getLines().size(); i++) { BxLine line = refs.getLines().get(i); Matcher nextMatcher = pattern.matcher(line.toText()); if (nextMatcher.matches()) { nextMatch = nextMatcher.group(1); break; } } if (prevMatch != null && objectMatch != null && Integer.parseInt(prevMatch) + 1 == Integer.parseInt(objectMatch)) { return 1; } if (nextMatch != null && objectMatch != null && Integer.parseInt(objectMatch) + 1 == Integer.parseInt(nextMatch)) { return 1; } } return 0; } }
2,943
36.74359
97
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/extraction/features/PrevEndsWithDotFeature.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.bibref.extraction.features; import java.util.regex.Pattern; import pl.edu.icm.cermine.bibref.extraction.model.BxDocumentBibReferences; import pl.edu.icm.cermine.structure.model.BxLine; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class PrevEndsWithDotFeature extends FeatureCalculator<BxLine, BxDocumentBibReferences> { @Override public double calculateFeatureValue(BxLine refLine, BxDocumentBibReferences refs) { if (refs.getLines().indexOf(refLine) == 0) { return 0.9; } String text = refs.getLines().get(refs.getLines().indexOf(refLine)-1).toText(); if (Pattern.matches("^.*\\d\\.$", text)) { return 1; } return Pattern.matches("^.*\\.$", text) ? 0.8 : 0; } }
1,614
35.704545
96
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/extraction/features/RelativeLengthFeature.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.bibref.extraction.features; import pl.edu.icm.cermine.bibref.extraction.model.BxDocumentBibReferences; import pl.edu.icm.cermine.structure.model.BxLine; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class RelativeLengthFeature extends FeatureCalculator<BxLine, BxDocumentBibReferences> { @Override public double calculateFeatureValue(BxLine refLine, BxDocumentBibReferences refs) { return refLine.getBounds().getWidth() / refs.getZone(refLine).getBounds().getWidth(); } }
1,358
36.75
95
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/extraction/features/SpaceBetweenLinesFeature.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.bibref.extraction.features; import pl.edu.icm.cermine.bibref.extraction.model.BxDocumentBibReferences; import pl.edu.icm.cermine.structure.model.BxLine; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class SpaceBetweenLinesFeature extends FeatureCalculator<BxLine, BxDocumentBibReferences> { @Override public double calculateFeatureValue(BxLine refLine, BxDocumentBibReferences refs) { double minSpace = Double.POSITIVE_INFINITY; double maxSpace = Double.NEGATIVE_INFINITY; double lineSpace = 0; BxLine prevLine = null; for (BxLine line : refs.getLines()) { if (prevLine != null && line.getBounds().getY() > prevLine.getBounds().getY()) { double difference = line.getBounds().getY() - prevLine.getBounds().getY(); if (minSpace > difference) { minSpace = difference; } if (maxSpace < difference) { maxSpace = difference; } if (line.equals(refLine)) { lineSpace = difference; } } prevLine = line; } if (refs.getLines().indexOf(refLine) == 0 && maxSpace > minSpace * 1.2) { return 0.5; } return (lineSpace > minSpace * 1.2) ? 0.5 : 0; } }
2,223
36.066667
98
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/extraction/features/RelativeStartFeature.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.bibref.extraction.features; import pl.edu.icm.cermine.bibref.extraction.model.BxDocumentBibReferences; import pl.edu.icm.cermine.structure.model.BxLine; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class RelativeStartFeature extends FeatureCalculator<BxLine, BxDocumentBibReferences> { @Override public double calculateFeatureValue(BxLine refLine, BxDocumentBibReferences refs) { return (refLine.getBounds().getX() - refs.getZone(refLine).getBounds().getX()) / refs.getZone(refLine).getBounds().getWidth(); } }
1,414
37.243243
94
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/extraction/features/EndsWithDotFeature.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.bibref.extraction.features; import java.util.regex.Pattern; import pl.edu.icm.cermine.bibref.extraction.model.BxDocumentBibReferences; import pl.edu.icm.cermine.structure.model.BxLine; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class EndsWithDotFeature extends FeatureCalculator<BxLine, BxDocumentBibReferences> { @Override public double calculateFeatureValue(BxLine refLine, BxDocumentBibReferences refs) { String text = refLine.toText(); if (Pattern.matches("^.*\\d\\.$", text)) { return 1; } return Pattern.matches("^.*\\.$", text) ? 0.5 : 0; } }
1,475
35
92
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/extraction/features/EndFeature.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.bibref.extraction.features; import pl.edu.icm.cermine.bibref.extraction.model.BxDocumentBibReferences; import pl.edu.icm.cermine.structure.model.BxLine; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class EndFeature extends FeatureCalculator<BxLine, BxDocumentBibReferences> { @Override public double calculateFeatureValue(BxLine refLine, BxDocumentBibReferences refs) { return refs.getZone(refLine).getBounds().getX() + refs.getZone(refLine).getBounds().getWidth() - refLine.getBounds().getX() - refLine.getBounds().getWidth(); } }
1,435
37.810811
102
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/extraction/features/RelativeStartTresholdFeature.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.bibref.extraction.features; import pl.edu.icm.cermine.bibref.extraction.model.BxDocumentBibReferences; import pl.edu.icm.cermine.structure.model.BxLine; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class RelativeStartTresholdFeature extends FeatureCalculator<BxLine, BxDocumentBibReferences> { private static final int LINE_INDENT_TRESHOLD = 6; @Override public double calculateFeatureValue(BxLine refLine, BxDocumentBibReferences refs) { return (refLine.getBounds().getX() - refs.getZone(refLine).getBounds().getX() > LINE_INDENT_TRESHOLD) ? 1 : 0; } }
1,450
37.184211
118
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/extraction/model/BibReferenceLineLabel.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.bibref.extraction.model; /** * Bibliographic reference line label. * * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public enum BibReferenceLineLabel { /** References block title line, eg. "References" */ BLOCK_LABEL, /** The first line of the reference (even if the only line) **/ BIBREF_START, /** The inner line of the reference (if the reference has at least three lines) */ BIBREF_INNER, /** The last line of the reference (if the reference has at leat two lines) */ BIBREF_END, }
1,295
33.105263
86
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/extraction/model/BxDocumentBibReferences.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.bibref.extraction.model; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import pl.edu.icm.cermine.structure.model.BxLine; import pl.edu.icm.cermine.structure.model.BxZone; /** * Stores BxDocument's bibliographic references lines with their labels. * * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class BxDocumentBibReferences { private static final int MAX_TITLE_LENGTH = 30; /** A list of references' lines */ private List<BxLine> lines = new ArrayList<BxLine>(); /** A map associating references' line with their zones */ private final Map<BxLine, BxZone> lineZones = new HashMap<BxLine, BxZone>(); /** A map associating references' lines with their labels */ private final Map<BxLine, BibReferenceLineLabel> lineLabels = new HashMap<BxLine, BibReferenceLineLabel>(); public void addZone(BxZone zone) { for (BxLine line : zone) { String normalized = line.toText().toLowerCase(Locale.ENGLISH).replaceAll("[^a-z]", ""); if (line.toText().length() < MAX_TITLE_LENGTH && zone.getChild(0) == line && (normalized.startsWith("refer") || normalized.startsWith("biblio") || normalized.startsWith("acknowled") || normalized.startsWith("conclus"))) { lines.clear(); lineZones.clear(); continue; } if (line.toText().replaceAll("[\\s\\u00A0]", "").isEmpty()) { continue; } lines.add(line); lineZones.put(line, zone); } } public List<BxLine> getLines() { return lines; } public void limit(int limit) { if (lines.size() > limit) { lines = lines.subList(lines.size()-limit, lines.size()); } } public BxZone getZone(BxLine line) { return lineZones.get(line); } public BibReferenceLineLabel getLabel(BxLine line) { return lineLabels.get(line); } public void setLabel(BxLine line, BibReferenceLineLabel label) { lineLabels.put(line, label); } }
2,969
32.370787
111
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/tools/NlmCitationExtractor.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.bibref.parsing.tools; import java.io.IOException; import java.util.*; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import org.jdom.Text; import org.jdom.filter.Filter; import org.jdom.input.SAXBuilder; import org.xml.sax.InputSource; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.bibref.parsing.model.CitationTokenLabel; /** * Citation extractor from NLM xml-s. * * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public final class NlmCitationExtractor { public static final List<String> TAGS_CITATION = Arrays.asList( "mixed-citation", "citation", "element-citation"); public static final String KEY_TEXT = "text"; private static final Map<String, CitationTokenLabel> TAGS_LABEL_MAP = new HashMap<String, CitationTokenLabel>(); static { TAGS_LABEL_MAP.put("article-title", CitationTokenLabel.ARTICLE_TITLE); TAGS_LABEL_MAP.put("conf-name", CitationTokenLabel.CONF); TAGS_LABEL_MAP.put("named-content", CitationTokenLabel.CONTENT); TAGS_LABEL_MAP.put("edition", CitationTokenLabel.TEXT); TAGS_LABEL_MAP.put("given-names", CitationTokenLabel.GIVENNAME); TAGS_LABEL_MAP.put("issue", CitationTokenLabel.ISSUE); TAGS_LABEL_MAP.put("id", CitationTokenLabel.ENUM); TAGS_LABEL_MAP.put("institution", CitationTokenLabel.INSTITUTION); TAGS_LABEL_MAP.put("fpage", CitationTokenLabel.PAGEF); TAGS_LABEL_MAP.put("lpage", CitationTokenLabel.PAGEL); TAGS_LABEL_MAP.put("publisher-loc", CitationTokenLabel.TEXT); TAGS_LABEL_MAP.put("publisher-name", CitationTokenLabel.TEXT); TAGS_LABEL_MAP.put("sc", CitationTokenLabel.SC); TAGS_LABEL_MAP.put("series", CitationTokenLabel.SERIES); TAGS_LABEL_MAP.put("source", CitationTokenLabel.SOURCE); TAGS_LABEL_MAP.put("surname", CitationTokenLabel.SURNAME); TAGS_LABEL_MAP.put("text", CitationTokenLabel.TEXT); TAGS_LABEL_MAP.put("uri", CitationTokenLabel.URI); TAGS_LABEL_MAP.put("volume", CitationTokenLabel.VOLUME); TAGS_LABEL_MAP.put("volume-series", CitationTokenLabel.VOLUME_SERIES); TAGS_LABEL_MAP.put("year", CitationTokenLabel.YEAR); } private NlmCitationExtractor() {} public static List<Citation> extractCitations(InputSource source) throws JDOMException, IOException { SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser"); builder.setValidation(false); builder.setFeature("http://xml.org/sax/features/validation", false); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); Document doc = builder.build(source); Iterator mixedCitations = doc.getDescendants(new Filter() { @Override public boolean matches(Object object) { return object instanceof Element && TAGS_CITATION.contains(((Element) object).getName()); } }); List<Citation> citationSet = new ArrayList<Citation>(); while (mixedCitations.hasNext()) { Citation citation = new Citation(); readElement((Element) mixedCitations.next(), citation); citationSet.add(citation); } return citationSet; } private static void readElement(Element element, Citation citation) { for (Object content : element.getContent()) { if (content instanceof Text) { String contentText = ((Text) content).getText(); if (!contentText.matches("^[\\s]*$")) { for (CitationToken token : CitationUtils.stringToCitation(contentText).getTokens()) { token.setStartIndex(token.getStartIndex() + citation.getText().length()); token.setEndIndex(token.getEndIndex() + citation.getText().length()); token.setLabel(TAGS_LABEL_MAP.get(KEY_TEXT)); citation.addToken(token); } citation.appendText(contentText); } else { citation.appendText(" "); } } else if (content instanceof Element) { Element contentElement = (Element) content; String contentElementName = contentElement.getName(); if (TAGS_LABEL_MAP.containsKey(contentElementName)) { for (CitationToken token : CitationUtils.stringToCitation(contentElement.getValue()).getTokens()) { token.setStartIndex(token.getStartIndex() + citation.getText().length()); token.setEndIndex(token.getEndIndex() + citation.getText().length()); token.setLabel(TAGS_LABEL_MAP.get(contentElementName)); citation.addToken(token); } citation.appendText(contentElement.getValue()); } else { readElement(contentElement, citation); } } } } }
6,220
45.425373
119
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/tools/FeatureList.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.bibref.parsing.tools; import java.util.Arrays; import pl.edu.icm.cermine.bibref.parsing.features.*; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; import pl.edu.icm.cermine.tools.classification.general.FeatureVectorBuilder; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public final class FeatureList { public static final FeatureVectorBuilder<CitationToken, Citation> VECTOR_BUILDER; static { VECTOR_BUILDER = new FeatureVectorBuilder<CitationToken, Citation>(); VECTOR_BUILDER.setFeatureCalculators(Arrays.<FeatureCalculator<CitationToken, Citation>>asList( new IsAllDigitsFeature(), new IsAllLettersFeature(), new IsAllLettersOrDigitsFeature(), new IsAllLowercaseFeature(), new IsAllRomanDigitsFeature(), new IsAllUppercaseFeature(), new IsAndFeature(), new IsCityFeature(), new IsClosingParenthesisFeature(), new IsClosingSquareBracketFeature(), new IsCommaFeature(), new IsCommonPublisherWordFeature(), new IsCommonSeriesWordFeature(), new IsCommonSourceWordFeature(), new IsDashBetweenWordsFeature(), new IsDashFeature(), new IsDigitFeature(), new IsDotFeature(), new IsLaquoFeature(), new IsLowercaseLetterFeature(), new IsNumberTextFeature(), new IsOpeningParenthesisFeature(), new IsOpeningSquareBracketFeature(), new IsPagesTextFeature(), new IsQuoteFeature(), new IsRaquoFeature(), new IsSingleQuoteBetweenWordsFeature(), new IsSlashFeature(), new IsUppercaseLetterFeature(), new IsUppercaseWordFeature(), new IsVolumeTextFeature(), new IsYearFeature(), new StartsWithUppercaseFeature(), new StartsWithWordMcFeature())); } private FeatureList() {} }
3,074
38.935065
103
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/tools/CitationUtils.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.bibref.parsing.tools; import com.google.common.collect.Lists; import java.util.ArrayList; import java.util.EnumMap; import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; import pl.edu.icm.cermine.bibref.model.BibEntry; import pl.edu.icm.cermine.bibref.model.BibEntryFieldType; import pl.edu.icm.cermine.bibref.model.BibEntryType; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.bibref.parsing.model.CitationTokenLabel; import pl.edu.icm.cermine.tools.PatternUtils; import pl.edu.icm.cermine.tools.PrefixTree; import pl.edu.icm.cermine.tools.classification.general.FeatureVector; import pl.edu.icm.cermine.tools.classification.general.FeatureVectorBuilder; /** * Citation utility class. * * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public final class CitationUtils { private static final Map<CitationTokenLabel, BibEntryFieldType> TO_BIBENTRY = new EnumMap<CitationTokenLabel, BibEntryFieldType>(CitationTokenLabel.class); static { TO_BIBENTRY.put(CitationTokenLabel.ARTICLE_TITLE, BibEntryFieldType.TITLE); TO_BIBENTRY.put(CitationTokenLabel.CONTENT, BibEntryFieldType.CONTENTS); TO_BIBENTRY.put(CitationTokenLabel.EDITION, BibEntryFieldType.EDITION); TO_BIBENTRY.put(CitationTokenLabel.PUBLISHER_NAME, BibEntryFieldType.PUBLISHER); TO_BIBENTRY.put(CitationTokenLabel.PUBLISHER_LOC, BibEntryFieldType.LOCATION); TO_BIBENTRY.put(CitationTokenLabel.SERIES, BibEntryFieldType.SERIES); TO_BIBENTRY.put(CitationTokenLabel.SOURCE, BibEntryFieldType.JOURNAL); TO_BIBENTRY.put(CitationTokenLabel.URI, BibEntryFieldType.URL); TO_BIBENTRY.put(CitationTokenLabel.VOLUME, BibEntryFieldType.VOLUME); TO_BIBENTRY.put(CitationTokenLabel.YEAR, BibEntryFieldType.YEAR); TO_BIBENTRY.put(CitationTokenLabel.ISSUE, BibEntryFieldType.NUMBER); TO_BIBENTRY.put(CitationTokenLabel.DOI, BibEntryFieldType.DOI); TO_BIBENTRY.put(CitationTokenLabel.PMID, BibEntryFieldType.PMID); TO_BIBENTRY.put(CitationTokenLabel.INSTITUTION, BibEntryFieldType.INSTITUTION); } private CitationUtils() {} public static Citation stringToCitation(String citation) { List<CitationToken> tokenList = new ArrayList<CitationToken>(); String text = citation; int actIndex = 0; while (text.length() > 0) { int end = 1; if (Character.isLetterOrDigit(text.charAt(0))) { end = 0; while (text.length() > end && Character.isLetterOrDigit(text.charAt(end))) { end++; } } String token = text.substring(0, end); if (!token.matches("\\s+")) { tokenList.add(new CitationToken(token, actIndex, actIndex + end)); } text = text.substring(end); actIndex += end; } return new Citation(citation, tokenList); } public static BibEntry citationToBibref(Citation citation) { String text = citation.getText(); Pattern doiPattern = Pattern.compile(".*(" + PatternUtils.DOI_PATTERN + ").*"); Matcher m = doiPattern.matcher(text); if (m.matches()) { for (CitationToken t :citation.getTokens()) { if (t.getStartIndex() >= m.start(1) && t.getEndIndex() <= m.end(1)) { t.setLabel(CitationTokenLabel.DOI); } } } Pattern pmidPattern = Pattern.compile(".*pmid\\s*:?\\s*(\\d+).*", Pattern.CASE_INSENSITIVE); m = pmidPattern.matcher(text); if (m.matches()) { for (CitationToken t :citation.getTokens()) { if (t.getStartIndex() >= m.start(1) && t.getEndIndex() <= m.end(1)) { t.setLabel(CitationTokenLabel.PMID); } } } List<CitationToken> tokens = new ArrayList<CitationToken>(); CitationToken token = null; for (CitationToken actToken : citation.getTokens()) { CitationTokenLabel actLabel = actToken.getLabel(); if (TO_BIBENTRY.containsKey(actLabel) || actLabel.equals(CitationTokenLabel.PAGEF) || actLabel.equals(CitationTokenLabel.PAGEL) || actLabel.equals(CitationTokenLabel.GIVENNAME) || actLabel.equals(CitationTokenLabel.SURNAME)) { if (token != null && actLabel.equals(token.getLabel())) { token.setEndIndex(actToken.getEndIndex()); token.setText(citation.getText().substring(token.getStartIndex(), token.getEndIndex())); } else { if (token != null) { tokens.add(token); } token = new CitationToken(actToken.getText(), actToken.getStartIndex(), actToken.getEndIndex(), actToken.getLabel()); } } else { if (token != null) { tokens.add(token); token = null; } } } if (token != null) { tokens.add(token); } BibEntry bibEntry = new BibEntry(BibEntryType.ARTICLE); String lcText = text.toLowerCase(Locale.ENGLISH); if (lcText.contains("tech report") || lcText.contains("technical report")) { bibEntry.setType(BibEntryType.TECHREPORT); } else if (lcText.contains("proceeding") || lcText.contains("conference") || lcText.contains("workshop") || lcText.contains("proc. ") || lcText.contains("conf. ")) { bibEntry.setType(BibEntryType.PROCEEDINGS); } bibEntry.setText(text); int i = 0; while (i < tokens.size()) { CitationToken actToken = tokens.get(i); CitationTokenLabel actLabel = actToken.getLabel(); CitationToken nextToken = null; if (i < tokens.size() - 1) { nextToken = tokens.get(i + 1); } if (TO_BIBENTRY.containsKey(actLabel)) { String value = text.substring(actToken.getStartIndex(), actToken.getEndIndex()); bibEntry.addField(TO_BIBENTRY.get(actLabel), value, actToken.getStartIndex(), actToken.getEndIndex()); i++; } else if (actLabel.equals(CitationTokenLabel.PAGEF)) { if (nextToken != null && nextToken.getLabel().equals(CitationTokenLabel.PAGEL)) { String pagef = text.substring(actToken.getStartIndex(), actToken.getEndIndex()); String pagel = text.substring(nextToken.getStartIndex(), nextToken.getEndIndex()); String value = pagef + "--" + pagel; bibEntry.addField(BibEntryFieldType.PAGES, value, actToken.getStartIndex(), nextToken.getEndIndex()); i += 2; } else { String value = text.substring(actToken.getStartIndex(), actToken.getEndIndex()); bibEntry.addField(BibEntryFieldType.PAGES, value, actToken.getStartIndex(), actToken.getEndIndex()); i++; } } else if (actLabel.equals(CitationTokenLabel.PAGEL)) { String value = text.substring(actToken.getStartIndex(), actToken.getEndIndex()); bibEntry.addField(BibEntryFieldType.PAGES, value, actToken.getStartIndex(), actToken.getEndIndex()); i++; } else if (actLabel.equals(CitationTokenLabel.GIVENNAME)) { if (nextToken != null && nextToken.getLabel().equals(CitationTokenLabel.SURNAME)) { String value = text.substring(nextToken.getStartIndex(), nextToken.getEndIndex()) + ", " + text.substring(actToken.getStartIndex(), actToken.getEndIndex()); bibEntry.addField(BibEntryFieldType.AUTHOR, value, actToken.getStartIndex(), nextToken.getEndIndex()); i += 2; } else { String value = text.substring(actToken.getStartIndex(), actToken.getEndIndex()); bibEntry.addField(BibEntryFieldType.AUTHOR, value, actToken.getStartIndex(), actToken.getEndIndex()); i++; } } else if (actLabel.equals(CitationTokenLabel.SURNAME)) { if (nextToken != null && nextToken.getLabel().equals(CitationTokenLabel.GIVENNAME)) { String value = text.substring(actToken.getStartIndex(), actToken.getEndIndex()) + ", " + text.substring(nextToken.getStartIndex(), nextToken.getEndIndex()); bibEntry.addField(BibEntryFieldType.AUTHOR, value, actToken.getStartIndex(), nextToken.getEndIndex()); i += 2; } else { String value = text.substring(actToken.getStartIndex(), actToken.getEndIndex()); bibEntry.addField(BibEntryFieldType.AUTHOR, value, actToken.getStartIndex(), actToken.getEndIndex()); i++; } } } return bibEntry; } public static List<String> citationToMalletInputFormat(Citation citation) { return citationToMalletInputFormat(citation, null, null, null, null); } public static List<String> citationToMalletInputFormat(Citation citation, Set<String> terms, PrefixTree journals, PrefixTree surnames, PrefixTree insts) { List<String> trainingExamples = new ArrayList<String>(); FeatureVectorBuilder vectorBuilder = FeatureList.VECTOR_BUILDER; List<CitationToken> tokens = citation.getTokens(); List<FeatureVector> featureVectors = new ArrayList<FeatureVector>(); List<String> tokenTexts = new ArrayList<String>(); for (CitationToken token : tokens) { tokenTexts.add(token.getText().toLowerCase(Locale.ENGLISH)); } Set<Integer> journalTokenIndices = new HashSet<Integer>(); if (journals != null) { for (int i = 0; i< tokenTexts.size(); i++) { int m = journals.match(Lists.newArrayList(tokenTexts.subList(i, tokenTexts.size()))); if (m > 0) { for (int j = i; j < i + m; j++) { journalTokenIndices.add(j); } } } } Set<Integer> instTokenIndices = new HashSet<Integer>(); if (insts != null) { for (int i = 0; i< tokenTexts.size(); i++) { int m = insts.match(Lists.newArrayList(tokenTexts.subList(i, tokenTexts.size()))); if (m > 0) { for (int j = i; j < i + m; j++) { instTokenIndices.add(j); } } } } Set<Integer> surnameTokenIndices = new HashSet<Integer>(); if (surnames != null) { for (int i = 0; i< tokenTexts.size(); i++) { int m = surnames.match(Lists.newArrayList(tokenTexts.subList(i, tokenTexts.size()))); if (m > 0) { for (int j = i; j < i + m; j++) { surnameTokenIndices.add(j); } } } } for (int i = 0; i < tokens.size(); i++) { CitationToken token = tokens.get(i); FeatureVector featureVector = vectorBuilder.getFeatureVector(token, citation); for (String featureName : featureVector.getFeatureNames()) { if (Double.isNaN(featureVector.getValue(featureName))) { throw new RuntimeException("Feature value is set to NaN: "+featureName); } } if (terms == null) { featureVector.addFeature("W=" + token.getText().toLowerCase(Locale.ENGLISH), 1); } else if (terms.contains(token.getText().toLowerCase(Locale.ENGLISH))) { featureVector.addFeature("W=" + token.getText().toLowerCase(Locale.ENGLISH), 1); } if (journalTokenIndices.contains(i)) { featureVector.addFeature("PartOfJournal", 1); } if (surnameTokenIndices.contains(i)) { featureVector.addFeature("PartOfSurname", 1); } if (instTokenIndices.contains(i)) { featureVector.addFeature("PartOfInst", 1); } featureVectors.add(featureVector); } for (int i = 0; i < tokens.size(); i++) { StringBuilder stringBuilder = new StringBuilder(); CitationTokenLabel label = tokens.get(i).getLabel(); if (i < tokens.size()-1 && label == CitationTokenLabel.TEXT && tokens.get(i+1).getLabel() != CitationTokenLabel.TEXT) { label = CitationTokenLabel.getTextBeforeLabel(tokens.get(i+1).getLabel()); } if (label != CitationTokenLabel.TEXT && CitationTokenLabel.getNormalizedLabel(label) != CitationTokenLabel.TEXT && CitationTokenLabel.getFirstLabel(label) != null && (i == 0 || label != tokens.get(i-1).getLabel())) { label = CitationTokenLabel.getFirstLabel(label); } stringBuilder.append(label); stringBuilder.append(" ---- "); if (i >= 3) { for (String n : featureVectors.get(i-3).getFeatureNames()) { if (featureVectors.get(i-3).getValue(n) > Double.MIN_VALUE) { stringBuilder.append(n); stringBuilder.append("@-3 "); } } } else { stringBuilder.append("<START>@-3 "); } if (i >= 2) { for (String n : featureVectors.get(i-2).getFeatureNames()) { if (featureVectors.get(i-2).getValue(n) > Double.MIN_VALUE) { stringBuilder.append(n); stringBuilder.append("@-2 "); } } } else { stringBuilder.append("<START>@-2 "); } if (i >= 1) { for (String n : featureVectors.get(i-1).getFeatureNames()) { if (featureVectors.get(i-1).getValue(n) > Double.MIN_VALUE) { stringBuilder.append(n); stringBuilder.append("@-1 "); } } } else { stringBuilder.append("<START>@-1 "); } for (String n : featureVectors.get(i).getFeatureNames()) { if (featureVectors.get(i).getValue(n) > Double.MIN_VALUE) { stringBuilder.append(n); stringBuilder.append(" "); } } if (i < featureVectors.size()-1) { for (String n : featureVectors.get(i+1).getFeatureNames()) { if (featureVectors.get(i+1).getValue(n) > Double.MIN_VALUE) { stringBuilder.append(n); stringBuilder.append("@1 "); } } } else { stringBuilder.append("<END>@1 "); } if (i < featureVectors.size()-2) { for (String n : featureVectors.get(i+2).getFeatureNames()) { if (featureVectors.get(i+2).getValue(n) > Double.MIN_VALUE) { stringBuilder.append(n); stringBuilder.append("@2 "); } } } else { stringBuilder.append("<END>@2 "); } if (i < featureVectors.size()-3) { for (String n : featureVectors.get(i+3).getFeatureNames()) { if (featureVectors.get(i+3).getValue(n) > Double.MIN_VALUE) { stringBuilder.append(n); stringBuilder.append("@3 "); } } } else { stringBuilder.append("<END>@3 "); } trainingExamples.add(stringBuilder.toString().trim()); } return trainingExamples; } }
17,600
45.19685
124
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsWordJrFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsWordJrFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().equalsIgnoreCase("jr")) ? 1 : 0; } }
1,297
35.055556
81
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsUppercaseWordFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsUppercaseWordFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { if (object.getText().length() < 2) { return 0; } if (!Character.isUpperCase(object.getText().charAt(0))) { return 0; } for (int i = 1; i < object.getText().length(); i++) { if (!Character.isLowerCase(object.getText().charAt(i))) { return 0; } } return 1; } }
1,613
33.340426
88
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsNumberTextFeature.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.bibref.parsing.features; import java.util.List; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsNumberTextFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { String text = object.getText(); List<CitationToken> tokens = context.getTokens(); int index = context.getTokens().indexOf(object); if (text.equalsIgnoreCase("no")) { return 1; } if (index + 1 < tokens.size() && text.equalsIgnoreCase("n") && tokens.get(index + 1).getText().equals("\u00B0")) { return 1; } if (index - 1 >= 0 && text.equalsIgnoreCase("\u00B0") && tokens.get(index - 1).getText().equals("n")) { return 1; } if (index + 1 < tokens.size() && text.equalsIgnoreCase("n") && tokens.get(index + 1).getText().equals(".")) { return 1; } if (index - 1 >= 0 && text.equalsIgnoreCase(".") && tokens.get(index - 1).getText().equals("n")) { return 1; } return 0; } }
2,127
35.689655
111
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsSingleQuoteBetweenWordsFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsSingleQuoteBetweenWordsFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { if (!object.getText().equals("\'") || object.getStartIndex() <= 0 || object.getEndIndex() >= context.getText().length()) { return 0; } return (Character.isLetter(context.getText().charAt(object.getStartIndex() - 1)) && Character.isLetter(context.getText().charAt(object.getEndIndex()))) ? 1 : 0; } }
1,611
39.3
98
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsCommonSurnamePartFeature.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.bibref.parsing.features; import java.util.List; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsCommonSurnamePartFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { String text = object.getText(); if (text.equalsIgnoreCase("van") || text.equalsIgnoreCase("de") || text.equalsIgnoreCase("der")) { return 1; } if (text.matches("^Mc[A-Z].*$")) { return 1; } List<CitationToken> tokens = context.getTokens(); int index = tokens.indexOf(object); if (index + 2 < tokens.size() && text.equals("O") && tokens.get(index + 1).getText().equals("'") && tokens.get(index + 2).getText().matches("^[A-Z].*$")) { return 1; } if (index + 1 < tokens.size() && index - 1 >= 0 && text.equals("'") && tokens.get(index - 1).getText().equals("O") && tokens.get(index + 1).getText().matches("^[A-Z].*$")) { return 1; } return 0; } }
2,098
36.482143
106
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsSlashFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsSlashFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().equals("/")) ? 1 : 0; } }
1,285
34.722222
81
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsWordAndFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsWordAndFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().equalsIgnoreCase("and")) ? 1 : 0; } }
1,299
35.111111
82
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsOpeningSquareBracketFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsOpeningSquareBracketFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().equals("[")) ? 1 : 0; } }
1,300
35.138889
95
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsWordTheoryFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsWordTheoryFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().equalsIgnoreCase("theory")) ? 1 : 0; } }
1,305
35.277778
85
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsVolumeTextFeature.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.bibref.parsing.features; import java.util.List; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsVolumeTextFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { String text = object.getText(); if (text.equalsIgnoreCase("vol") || text.equalsIgnoreCase("volume") || text.equalsIgnoreCase("tom") || text.equalsIgnoreCase("tome")) { return 1; } List<CitationToken> tokens = context.getTokens(); int index = tokens.indexOf(object); if (index + 2 < tokens.size() && text.equalsIgnoreCase("t")) { if (tokens.get(index + 1).getText().matches("^\\d+$")) { return 1; } if (tokens.get(index + 1).getText().equals(".") && tokens.get(index + 2).getText().matches("^\\d+$")) { return 1; } } return 0; } }
1,956
36.634615
115
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsClosingSquareBracketFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsClosingSquareBracketFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().equals("]")) ? 1 : 0; } }
1,300
35.138889
95
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/StartingNumberFeature.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.bibref.parsing.features; import java.util.List; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class StartingNumberFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { List<CitationToken> tokens = context.getTokens(); int index = context.getTokens().indexOf(object); if (tokens.size() > 0 && tokens.get(0).getText().matches("^\\d+$") && index == 0) { return 1; } if (tokens.size() > 1) { String two = tokens.get(0).getText() + tokens.get(1).getText(); if (two.matches("^\\d+\\.$") && index < 2) { return 1; } } if (tokens.size() > 2) { String three = tokens.get(0).getText() + tokens.get(1).getText() + tokens.get(2).getText(); if (three.matches("^\\[\\d+\\]$") && index < 3) { return 1; } if (three.matches("^.\\d+\\.$") && index < 3) { return 1; } } return 0; } }
2,085
33.766667
103
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsLaquoFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsLaquoFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { String text = object.getText(); return (text.length() == 1 && text.charAt(0) == '\u00AB') ? 1 : 0; } }
1,345
35.378378
81
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsQuoteFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsQuoteFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().equals("\"")) ? 1 : 0; } }
1,286
34.75
81
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsWordHttpFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsWordHttpFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().equalsIgnoreCase("http") || object.getText().equalsIgnoreCase("https") || object.getText().equalsIgnoreCase("www")) ? 1 : 0; } }
1,407
37.054054
103
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsCityFeature.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.bibref.parsing.features; import java.util.Arrays; import java.util.List; import java.util.Locale; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsCityFeature extends FeatureCalculator<CitationToken, Citation> { private static final List<String> KEYWORDS = Arrays.asList( "angeles", "antonio", "amsterdam", "ankara", "athens", "bangkok", "basel", "beijing", "belgrade", "berkeley", "berlin", "bern", "bologna", "bombay", "boston", "bratislava", "brussels", "bucharest", "budapest", "cambridge", "calgary", "chicago", "copenhagen", "dallas", "delhi", "dhaka", "diego", "dordrecht", "dublin", "edmonton", "francisco", "grenoble", "göttingen", "heidelberg", "helsinki", "houston", "indianapolis", "istanbul", "jakarta", "jacksonville", "jose", "karachi", "kiev", "leipzig", "lisbon", "ljubljana", "london", "londres", "los", "madrid", "manila", "mass", "minsk", "montreal", "moscou", "moscow", "mumbai", "new", "orsay", "oslo", "ottawa", "oxford", "paris", "phoenix", "philadelphia", "prague", "princeton", "providence", "reading", "reykjavik", "riga", "roma", "rome", "san", "sarajevo", "seoul", "shanghai", "skopje", "sofia", "stockholm", "tallinn", "tehran", "tirana", "tokyo", "toronto", "toulouse", "vancouver", "vienna", "vilnius", "warsaw", "warszawa", "york", "zagreb"); @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (KEYWORDS.contains(object.getText().toLowerCase(Locale.ENGLISH))) ? 1 : 0; } }
2,753
41.369231
115
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsAllRomanDigitsFeature.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.bibref.parsing.features; import org.apache.commons.lang.ArrayUtils; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.CharacterUtils; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsAllRomanDigitsFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { char[] charArray = object.getText().toCharArray(); for (int i = 0; i < charArray.length; i++) { if (!ArrayUtils.contains(CharacterUtils.ROMAN_CHARS, charArray[i])) { return 0; } } return 1; } }
1,594
35.25
89
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsYearFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.TextUtils; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsYearFeature extends FeatureCalculator<CitationToken, Citation> { private static final int MIN_YEAR = 1800; private static final int MAX_YEAR = 2100; @Override public double calculateFeatureValue(CitationToken object, Citation context) { return TextUtils.isNumberBetween(object.getText(), MIN_YEAR, MAX_YEAR) ? 1 : 0; } }
1,457
35.45
87
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsWordLeFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsWordLeFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().equalsIgnoreCase("le")) ? 1 : 0; } }
1,297
35.055556
81
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsPagesTextFeature.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.bibref.parsing.features; import java.util.List; import org.apache.commons.lang.ArrayUtils; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsPagesTextFeature extends FeatureCalculator<CitationToken, Citation> { private static final String[] PAGES_STRINGS = {"p", "pp", "pages"}; @Override public double calculateFeatureValue(CitationToken object, Citation context) { String text = object.getText(); int index = context.getTokens().indexOf(object); List<CitationToken> tokens = context.getTokens(); if (ArrayUtils.contains(PAGES_STRINGS, text)) { return 1; } if (index - 1 >= 0 && text.equals(".") && ArrayUtils.contains(PAGES_STRINGS, tokens.get(index - 1).getText())) { return 1; } return 0; } }
1,792
34.86
120
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsCommonSeriesWordFeature.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.bibref.parsing.features; import java.util.Arrays; import java.util.List; import java.util.Locale; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsCommonSeriesWordFeature extends FeatureCalculator<CitationToken, Citation> { private static final List<String> KEYWORDS = Arrays.asList( "ann", "appl", "applied", "astérisque", "graduate", "henri", "inst", "lect", "lecture", "lectures", "math", "mathematical", "mathematics", "maths", "note", "notes", "physics", "poincaré", "pure", "research", "series", "soc", "springer", "statistics", "texts" ); @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (KEYWORDS.contains(object.getText().toLowerCase(Locale.ENGLISH))) ? 1 : 0; } }
1,887
34.622642
91
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsAllLettersFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsAllLettersFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { char[] charArray = object.getText().toCharArray(); for (int i = 0; i < charArray.length; i++) { if (!Character.isLetter(charArray[i])) { return 0; } } return 1; } }
1,468
33.97619
85
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsOpeningParenthesisFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsOpeningParenthesisFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().equals("(")) ? 1 : 0; } }
1,298
35.083333
93
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsAllLettersOrDigitsFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsAllLettersOrDigitsFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { char[] charArray = object.getText().toCharArray(); for (int i = 0; i < charArray.length; i++) { if (!Character.isLetterOrDigit(charArray[i])) { return 0; } } return 1; } }
1,483
34.333333
93
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class DigitRelativeCountFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { char[] charArray = object.getText().toCharArray(); int digits = 0; for (int i = 0; i < charArray.length; i++) { if (Character.isDigit(charArray[i])) { digits++; } } return (double) digits / (double) object.getText().length(); } }
1,548
34.204545
91
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsAndFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsAndFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().equalsIgnoreCase("and") || object.getText().equals("&")) ? 1 : 0; } }
1,327
35.888889
98
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsWordTheFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsWordTheFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().equalsIgnoreCase("the")) ? 1 : 0; } }
1,299
35.111111
82
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsTextWordFeature.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.bibref.parsing.features; import java.util.Arrays; import java.util.List; import java.util.Locale; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsTextWordFeature extends FeatureCalculator<CitationToken, Citation> { private static final String FEATURE_NAME = "IsOtherWord"; @Override public String getFeatureName() { return FEATURE_NAME; } private static final List<String> KEYWORDS = Arrays.asList( "preprint", "preparation", "submitted", "phd", "thesis", "available", "thèse", "doctorale", "paraître", "appear", "proceeding", "proceedings"); @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (KEYWORDS.contains(object.getText().toLowerCase(Locale.ENGLISH))) ? 1 : 0; } }
1,779
34.6
115
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsClosingParenthesisFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsClosingParenthesisFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().equals(")")) ? 1 : 0; } }
1,298
35.083333
93
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsDigitFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsDigitFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().matches("^\\d$")) ? 1 : 0; } }
1,290
34.861111
81
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsDashBetweenWordsFeature.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.bibref.parsing.features; import org.apache.commons.lang.ArrayUtils; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.CharacterUtils; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsDashBetweenWordsFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { String text = object.getText(); if (text.length() != 1 || object.getStartIndex() <= 0 || object.getEndIndex() >= context.getText().length()) { return 0; } if (!ArrayUtils.contains(CharacterUtils.DASH_CHARS, text.charAt(0))) { return 0; } return (Character.isLetter(context.getText().charAt(object.getStartIndex() - 1)) && Character.isLetter(context.getText().charAt(object.getEndIndex()))) ? 1 : 0; } }
1,819
38.565217
118
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/InitialsInParenthesesFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class InitialsInParenthesesFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { String text = object.getText(); int index = context.getTokens().indexOf(object); if (text.matches("^[A-Z]$")) { if (index - 1 < 0 || index + 2 >= context.getTokens().size()) { return 0; } if (context.getTokens().get(index - 1).getText().equals("(") && context.getTokens().get(index + 1).getText().equals(".") && context.getTokens().get(index + 2).getText().equals(")")) { return 1; } } if (text.equals(".")) { if (index - 2 < 0 || index + 1 >= context.getTokens().size()) { return 0; } if (context.getTokens().get(index - 2).getText().equals("(") && context.getTokens().get(index - 1).getText().matches("^[A-Z]$") && context.getTokens().get(index + 1).getText().equals(")")) { return 1; } } if (text.matches("^[A-Z][a-z]+$")) { if (index - 1 < 0 || index + 1 >= context.getTokens().size()) { return 0; } if (context.getTokens().get(index - 1).getText().equals("(") && context.getTokens().get(index + 1).getText().equals(")")) { return 1; } } return 0; } }
2,609
37.382353
94
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsCommonPublisherWordFeature.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.bibref.parsing.features; import java.util.Arrays; import java.util.List; import java.util.Locale; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsCommonPublisherWordFeature extends FeatureCalculator<CitationToken, Citation> { private static final List<String> KEYWORDS = Arrays.asList( "academic", "birkhäuser", "cambridge", "company", "dunod", "france", "gauthier", "hermann", "holland", "interscience", "john", "masson", "math", "north", "nostrand", "paris", "polytechnique", "press", "princeton", "publ", "publishers", "sons", "springer", "univ", "université", "university", "verlag", "villars", "wiley", "world" ); @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (KEYWORDS.contains(object.getText().toLowerCase(Locale.ENGLISH))) ? 1 : 0; } }
2,008
34.245614
94
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsAllDigitsFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsAllDigitsFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { char[] charArray = object.getText().toCharArray(); for (int i = 0; i < charArray.length; i++) { if (!Character.isDigit(charArray[i])) { return 0; } } return 1; } }
1,466
33.928571
84
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsWordDeFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsWordDeFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().equalsIgnoreCase("de")) ? 1 : 0; } }
1,297
35.055556
81
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsUppercaseLetterFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsUppercaseLetterFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().matches("^[A-Z]$")) ? 1 : 0; } }
1,302
35.194444
90
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/StartsWithUppercaseFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class StartsWithUppercaseFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().length() > 0 && Character.isUpperCase(object.getText().charAt(0))) ? 1 : 0; } }
1,351
36.555556
108
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsAllLowercaseFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsAllLowercaseFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { char[] charArray = object.getText().toCharArray(); for (int i = 0; i < charArray.length; i++) { if (!Character.isLowerCase(charArray[i])) { return 0; } } return 1; } }
1,473
34.095238
87
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/StartsWithWordMcFeature.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.bibref.parsing.features; import java.util.Locale; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class StartsWithWordMcFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().toLowerCase(Locale.ENGLISH).startsWith("mc")) ? 1 : 0; } }
1,352
35.567568
89
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/LengthFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class LengthFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (double) object.getText().length(); } }
1,280
34.583333
81
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsRaquoFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsRaquoFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { String text = object.getText(); return (text.length() == 1 && text.charAt(0) == '\u00BB') ? 1 : 0; } }
1,345
35.378378
81
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/UppercaseRelativeCountFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class UppercaseRelativeCountFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { char[] charArray = object.getText().toCharArray(); int uppercase = 0; for (int i = 0; i < charArray.length; i++) { if (Character.isUpperCase(charArray[i])) { uppercase++; } } return (double) uppercase / (double) object.getText().length(); } }
1,565
34.590909
95
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsDashFeature.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.bibref.parsing.features; import org.apache.commons.lang.ArrayUtils; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.CharacterUtils; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsDashFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { String text = object.getText(); return (text.length() == 1 && ArrayUtils.contains(CharacterUtils.DASH_CHARS, text.charAt(0))) ? 1 : 0; } }
1,472
36.769231
110
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsCommonSourceWordFeature.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.bibref.parsing.features; import java.util.Arrays; import java.util.List; import java.util.Locale; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsCommonSourceWordFeature extends FeatureCalculator<CitationToken, Citation> { private static final List<String> KEYWORDS = Arrays.asList( "acad", "acta", "algebra", "amer", "anal", "ann", "annales", "annals", "appl", "bourbaki", "bull", "comm", "comptes", "fields", "fourier", "geom", "inst", "invent", "journal", "lett", "mat", "math", "mathematical", "mathematics", "phys", "physics", "probab", "proc", "publ", "pure", "séminaire", "sc", "sci", "sciences", "soc", "studies", "theory", "trans", "univ" ); @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (KEYWORDS.contains(object.getText().toLowerCase(Locale.ENGLISH))) ? 1 : 0; } }
2,004
36.12963
91
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/LetterRelativeCountFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class LetterRelativeCountFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { char[] charArray = object.getText().toCharArray(); int letters = 0; for (int i = 0; i < charArray.length; i++) { if (Character.isLetter(charArray[i])) { letters++; } } return (double) letters / (double) object.getText().length(); } }
1,553
34.318182
92
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsAllUppercaseFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsAllUppercaseFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { char[] charArray = object.getText().toCharArray(); for (int i = 0; i < charArray.length; i++) { if (!Character.isUpperCase(charArray[i])) { return 0; } } return 1; } }
1,473
34.095238
87
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsDotFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsDotFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().equals(".")) ? 1 : 0; } }
1,283
34.666667
81
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/LowercaseRelativeCountFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class LowercaseRelativeCountFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { char[] charArray = object.getText().toCharArray(); int lowercase = 0; for (int i = 0; i < charArray.length; i++) { if (Character.isLowerCase(charArray[i])) { lowercase++; } } return (double) lowercase / (double) object.getText().length(); } }
1,565
34.590909
95
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsLowercaseLetterFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsLowercaseLetterFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().matches("^[a-z]$")) ? 1 : 0; } }
1,301
36.2
90
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/features/IsCommaFeature.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.bibref.parsing.features; import pl.edu.icm.cermine.bibref.parsing.model.Citation; import pl.edu.icm.cermine.bibref.parsing.model.CitationToken; import pl.edu.icm.cermine.tools.classification.general.FeatureCalculator; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class IsCommaFeature extends FeatureCalculator<CitationToken, Citation> { @Override public double calculateFeatureValue(CitationToken object, Citation context) { return (object.getText().equals(",")) ? 1 : 0; } }
1,285
34.722222
81
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/model/CitationToken.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.bibref.parsing.model; /** * Citation token. * * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class CitationToken { private String text; private CitationTokenLabel label; private int startIndex; private int endIndex; public CitationToken(String text, int startIndex, int endIndex, CitationTokenLabel label) { this.text = text; this.startIndex = startIndex; this.endIndex = endIndex; this.label = label; } public CitationToken(String text, int startIndex, int endIndex) { this(text, startIndex, endIndex, CitationTokenLabel.TEXT); } public CitationTokenLabel getLabel() { return label; } public void setLabel(CitationTokenLabel label) { this.label = label; } public String getText() { return text; } public void setText(String text) { this.text = text; } public void appendText(String text) { this.text += text; } public int getEndIndex() { return endIndex; } public void setEndIndex(int endIndex) { this.endIndex = endIndex; } public int getStartIndex() { return startIndex; } public void setStartIndex(int startIndex) { this.startIndex = startIndex; } }
2,065
24.506173
95
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/model/Citation.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.bibref.parsing.model; import java.util.ArrayList; import java.util.List; /** * Represents a citation as a sequence of citation tokens. * * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class Citation { private String text; private List<CitationToken> tokens; private List<CitationToken> consolidated; public Citation(String text, List<CitationToken> tokens) { this.text = text; this.tokens = tokens; } public Citation(String text) { this(text, new ArrayList<CitationToken>()); } public Citation() { this(""); } public String getText() { return text; } public List<CitationToken> getTokens() { return tokens; } public List<CitationToken> getConcatenatedTokens() { if (consolidated == null) { consolidated = new ArrayList<CitationToken>(); CitationTokenLabel prevLabel = null; String prevText = ""; int prevStart = 0; int prevEnd = 0; for (CitationToken token : tokens) { if (prevLabel != token.getLabel()) { if (prevLabel != null) { consolidated.add(new CitationToken(prevText, prevStart, prevEnd, prevLabel)); } prevLabel = token.getLabel(); prevText = token.getText(); prevStart = token.getStartIndex(); prevEnd = token.getEndIndex(); } else { prevEnd = token.getEndIndex(); prevText += " "; prevText += token.getText(); } } if (prevLabel != null) { consolidated.add(new CitationToken(prevText, prevStart, prevEnd, prevLabel)); } } return consolidated; } public void setText(String text) { this.text = text; } public void addToken(CitationToken token) { tokens.add(token); } public void appendText(String text) { this.text += text; } }
2,890
28.5
101
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/parsing/model/CitationTokenLabel.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.bibref.parsing.model; import java.util.EnumMap; import java.util.Map; /** * Citation token label. * * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public enum CitationTokenLabel { ARTICLE_TITLE, ARTICLE_TITLE_FIRST, CONF, CONF_FIRST, CONTENT, CONTENT_FIRST, DOI, EDITION, ENUM, GIVENNAME, GIVENNAME_FIRST, ISSUE, INSTITUTION, INSTITUTION_FIRST, PAGEF, PAGEL, PMID, PUBLISHER_LOC, PUBLISHER_LOC_FIRST, PUBLISHER_NAME, PUBLISHER_NAME_FIRST, SC, SC_FIRST, SERIES, SOURCE, SOURCE_FIRST, SURNAME, SURNAME_FIRST, TEXT, TEXT_BEFORE_ARTICLE_TITLE, TEXT_BEFORE_CONF, TEXT_BEFORE_CONTENT, TEXT_BEFORE_DOI, TEXT_BEFORE_EDITION, TEXT_BEFORE_ENUM, TEXT_BEFORE_GIVENNAME, TEXT_BEFORE_ISSUE, TEXT_BEFORE_INSTITUTION, TEXT_BEFORE_PAGEF, TEXT_BEFORE_PAGEL, TEXT_BEFORE_PMID, TEXT_BEFORE_PUBLISHER_LOC, TEXT_BEFORE_PUBLISHER_NAME, TEXT_BEFORE_SC, TEXT_BEFORE_SERIES, TEXT_BEFORE_SOURCE, TEXT_BEFORE_SURNAME, TEXT_BEFORE_URI, TEXT_BEFORE_VOLUME, TEXT_BEFORE_VOLUME_SERIES, TEXT_BEFORE_YEAR, URI, VOLUME, VOLUME_SERIES, YEAR; private static final Map<CitationTokenLabel, CitationTokenLabel> FIRST_LABELS = new EnumMap<CitationTokenLabel, CitationTokenLabel>(CitationTokenLabel.class); private static final Map<CitationTokenLabel, CitationTokenLabel> TEXT_BEFORE_LABELS = new EnumMap<CitationTokenLabel, CitationTokenLabel>(CitationTokenLabel.class); private static final Map<CitationTokenLabel, CitationTokenLabel> NORMALIZE_LABELS = new EnumMap<CitationTokenLabel, CitationTokenLabel>(CitationTokenLabel.class); static { FIRST_LABELS.put(ARTICLE_TITLE, ARTICLE_TITLE_FIRST); FIRST_LABELS.put(CONF, CONF_FIRST); FIRST_LABELS.put(CONTENT, CONTENT_FIRST); FIRST_LABELS.put(GIVENNAME, GIVENNAME_FIRST); FIRST_LABELS.put(INSTITUTION, INSTITUTION_FIRST); FIRST_LABELS.put(PUBLISHER_LOC, PUBLISHER_LOC_FIRST); FIRST_LABELS.put(PUBLISHER_NAME, PUBLISHER_NAME_FIRST); FIRST_LABELS.put(SC, SC_FIRST); FIRST_LABELS.put(SOURCE, SOURCE_FIRST); FIRST_LABELS.put(SURNAME, SURNAME_FIRST); TEXT_BEFORE_LABELS.put(ARTICLE_TITLE, TEXT_BEFORE_ARTICLE_TITLE); TEXT_BEFORE_LABELS.put(CONF, TEXT_BEFORE_CONF); TEXT_BEFORE_LABELS.put(CONTENT, TEXT_BEFORE_CONTENT); TEXT_BEFORE_LABELS.put(DOI, TEXT_BEFORE_DOI); TEXT_BEFORE_LABELS.put(EDITION, TEXT_BEFORE_EDITION); TEXT_BEFORE_LABELS.put(ENUM, TEXT_BEFORE_ENUM); TEXT_BEFORE_LABELS.put(GIVENNAME, TEXT_BEFORE_GIVENNAME); TEXT_BEFORE_LABELS.put(ISSUE, TEXT_BEFORE_ISSUE); TEXT_BEFORE_LABELS.put(INSTITUTION, TEXT_BEFORE_INSTITUTION); TEXT_BEFORE_LABELS.put(PAGEF, TEXT_BEFORE_PAGEF); TEXT_BEFORE_LABELS.put(PAGEL, TEXT_BEFORE_PAGEL); TEXT_BEFORE_LABELS.put(PMID, TEXT_BEFORE_PMID); TEXT_BEFORE_LABELS.put(PUBLISHER_LOC, TEXT_BEFORE_PUBLISHER_LOC); TEXT_BEFORE_LABELS.put(PUBLISHER_NAME, TEXT_BEFORE_PUBLISHER_NAME); TEXT_BEFORE_LABELS.put(SC, TEXT_BEFORE_SC); TEXT_BEFORE_LABELS.put(SERIES, TEXT_BEFORE_SERIES); TEXT_BEFORE_LABELS.put(SOURCE, TEXT_BEFORE_SOURCE); TEXT_BEFORE_LABELS.put(SURNAME, TEXT_BEFORE_SURNAME); TEXT_BEFORE_LABELS.put(URI, TEXT_BEFORE_URI); TEXT_BEFORE_LABELS.put(VOLUME, TEXT_BEFORE_VOLUME); TEXT_BEFORE_LABELS.put(VOLUME_SERIES, TEXT_BEFORE_VOLUME_SERIES); TEXT_BEFORE_LABELS.put(YEAR, TEXT_BEFORE_YEAR); NORMALIZE_LABELS.put(TEXT_BEFORE_ARTICLE_TITLE, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_CONF, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_CONTENT, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_DOI, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_EDITION, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_ENUM, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_GIVENNAME, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_ISSUE, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_INSTITUTION, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_PAGEF, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_PAGEL, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_PMID, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_PUBLISHER_LOC, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_PUBLISHER_NAME, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_SC, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_SERIES, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_SOURCE, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_SURNAME, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_URI, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_VOLUME, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_VOLUME_SERIES, TEXT); NORMALIZE_LABELS.put(TEXT_BEFORE_YEAR, TEXT); NORMALIZE_LABELS.put(ARTICLE_TITLE_FIRST, ARTICLE_TITLE); NORMALIZE_LABELS.put(CONF_FIRST, CONF); NORMALIZE_LABELS.put(CONTENT_FIRST, CONTENT); NORMALIZE_LABELS.put(GIVENNAME_FIRST, GIVENNAME); NORMALIZE_LABELS.put(PUBLISHER_LOC_FIRST, PUBLISHER_LOC); NORMALIZE_LABELS.put(PUBLISHER_NAME_FIRST, PUBLISHER_NAME); NORMALIZE_LABELS.put(SC_FIRST, SC); NORMALIZE_LABELS.put(SOURCE_FIRST, SOURCE); NORMALIZE_LABELS.put(SURNAME_FIRST, SURNAME); NORMALIZE_LABELS.put(INSTITUTION_FIRST, INSTITUTION); } private static CitationTokenLabel mapLabel(Map<CitationTokenLabel, CitationTokenLabel> map, CitationTokenLabel label) { if (!map.containsKey(label)) { return null; } return map.get(label); } public static CitationTokenLabel getFirstLabel(CitationTokenLabel label) { return mapLabel(FIRST_LABELS, label); } public static CitationTokenLabel getTextBeforeLabel(CitationTokenLabel label) { return mapLabel(TEXT_BEFORE_LABELS, label); } public static CitationTokenLabel getNormalizedLabel(CitationTokenLabel label) { return mapLabel(NORMALIZE_LABELS, label); } }
7,527
39.691892
95
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/model/BibEntryField.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.bibref.model; /** * BibEntry field. * * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class BibEntryField { private String text; private int startIndex; private int endIndex; public BibEntryField(String text) { this(text, -1, -1); } public BibEntryField(String text, int startIndex, int endIndex) { this.text = text; this.startIndex = startIndex; this.endIndex = endIndex; } public String getText() { return text; } public void setText(String value) { this.text = value; } public int getStartIndex() { return startIndex; } public int getEndIndex() { return endIndex; } public void setIndexes(int startIndex, int endIndex) { this.startIndex = startIndex; this.endIndex = endIndex; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final BibEntryField other = (BibEntryField) obj; if ((this.text == null) ? (other.text != null) : !this.text.equals(other.text)) { return false; } if (this.startIndex != other.startIndex) { return false; } return this.endIndex == other.endIndex; } @Override public int hashCode() { int hash = 7; hash = 53 * hash + (this.text != null ? this.text.hashCode() : 0); hash = 53 * hash + this.startIndex; hash = 53 * hash + this.endIndex; return hash; } }
2,397
25.351648
89
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/model/BibEntryFieldType.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.bibref.model; /** * Bibliographic reference field types. * * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public enum BibEntryFieldType { ABSTRACT ("abstract"), ADDRESS ("address"), AFFILIATION ("affiliation"), ANNOTE ("annote"), AUTHOR ("author"), BOOKTITLE ("booktitle"), CHAPTER ("chapter"), CONTENTS ("contents"), COPYRIGHT ("copyright"), CROSSREF ("crossref"), DOI ("doi"), EDITION ("edition"), EDITOR ("editor"), HOWPUBLISHED ("howpublished"), INSTITUTION ("institution"), ISBN ("isbn"), ISSN ("issn"), JOURNAL ("journal"), KEY ("key"), KEYWORDS ("keywords"), LANGUAGE ("language"), LCCN ("lccn"), LOCATION ("location"), MONTH ("month"), MRNUMBER ("mrnumber"), NOTE ("note"), NUMBER ("number"), ORGANIZATION ("organization"), PAGES ("pages"), PMID ("pmid"), PUBLISHER ("publisher"), SCHOOL ("school"), SERIES ("series"), TITLE ("title"), TYPE ("type"), URL ("url"), VOLUME ("volume"), YEAR ("year"); private final String type; BibEntryFieldType(String type) { this.type = type; } public String getType() { return type; } public static BibEntryFieldType ofType(String type) { for (BibEntryFieldType t : BibEntryFieldType.values()) { if (t.getType().equals(type)) { return t; } } return null; } }
2,565
28.837209
78
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/model/BibEntryType.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.bibref.model; /** * Bibliographic reference types. * * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public enum BibEntryType { ARTICLE ("article"), BOOK ("book"), BOOKLET ("booklet"), INBOOK ("inbook"), INCOLLECTION ("incollection"), INPROCEEDINGS ("inproceedings"), MANUAL ("manual"), MASTERSTHESIS ("mastersthesis"), MISC ("misc"), PHDTHESIS ("phdthesis"), PROCEEDINGS ("proceedings"), TECHREPORT ("techreport"), UNPUBLISHED ("unpublished"); private final String type; private BibEntryType(String type) { this.type = type; } public String getType() { return type; } public static BibEntryType ofType(String type) { for (BibEntryType t : BibEntryType.values()) { if (t.getType().equals(type)) { return t; } } return null; } }
1,762
27.901639
78
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/model/BibEntry.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.bibref.model; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.lang.StringUtils; /** * Bibliographic reference entry, modelled after BibTeX format. * * @author Lukasz Bolikowski (bolo@icm.edu.pl) */ public class BibEntry { private BibEntryType type; private String key; private String text; private final Map<BibEntryFieldType, List<BibEntryField>> fields = new EnumMap<BibEntryFieldType, List<BibEntryField>>(BibEntryFieldType.class); public BibEntry() { } public BibEntry(BibEntryType type) { this.type = type; } public BibEntry(BibEntryType type, String key) { this.type = type; this.key = key; } public BibEntryType getType() { return type; } public BibEntry setType(BibEntryType type) { this.type = type; return this; } public String getKey() { return key; } public BibEntry setKey(String key) { this.key = key; return this; } public String getText() { return text; } public BibEntry setText(String text) { this.text = text; return this; } public Set<BibEntryFieldType> getFieldKeys() { return fields.keySet(); } public BibEntryField getFirstField(BibEntryFieldType key) { List<BibEntryField> fieldList = fields.get(key); if (fieldList == null) { return null; } return (fieldList.isEmpty()) ? null : fieldList.get(0); } public String getFirstFieldValue(BibEntryFieldType key) { BibEntryField field = getFirstField(key); if (field == null) { return null; } return field.getText(); } public List<BibEntryField> getAllFields(BibEntryFieldType key) { return (fields.get(key) == null) ? new ArrayList<BibEntryField>() : fields.get(key); } public List<String> getAllFieldValues(BibEntryFieldType key) { List<BibEntryField> beFields = getAllFields(key); List<String> values = new ArrayList<String>(); for (BibEntryField field : beFields) { values.add(field.getText()); } return values; } public BibEntry addField(BibEntryFieldType key, String value) { if (key == null || value == null) { return this; } return addField(key, new BibEntryField(value)); } public BibEntry setField(BibEntryFieldType key, String value) { if (key == null || value == null) { return this; } return setField(key, new BibEntryField(value)); } public BibEntry addField(BibEntryFieldType key, String value, int startIndex, int endIndex) { if (key == null || value == null) { return this; } return addField(key, new BibEntryField(value, startIndex, endIndex)); } public BibEntry setField(BibEntryFieldType key, String value, int startIndex, int endIndex) { if (key == null || value == null) { return this; } return setField(key, new BibEntryField(value, startIndex, endIndex)); } public BibEntry addField(BibEntryFieldType key, BibEntryField field) { if (key == null || field == null) { return this; } if (fields.get(key) == null) { fields.put(key, new ArrayList<BibEntryField>()); } fields.get(key).add(field); return this; } public BibEntry setField(BibEntryFieldType key, BibEntryField field) { if (key == null || field == null) { return this; } if (fields.get(key) != null) { fields.get(key).clear(); } return addField(key, field); } public BibEntry removeField(BibEntryFieldType key) { fields.remove(key); return this; } public String generateKey() { String result = "Unknown"; if (fields.get(BibEntryFieldType.AUTHOR) != null && fields.get(BibEntryFieldType.AUTHOR).size() > 0) { result = fields.get(BibEntryFieldType.AUTHOR).get(0).getText(); Pattern pattern = Pattern.compile("^[\\p{L}' ]+"); Matcher matcher = pattern.matcher(result); result = matcher.find() ? matcher.group().replaceAll("[' ]", "") : "Unknown"; } if (fields.get(BibEntryFieldType.YEAR) != null) { result += fields.get(BibEntryFieldType.YEAR).get(0).getText(); } return result; } protected String escape(String text) { return text.replace("{", "\\{").replace("}", "\\}").replace("_", "\\_"); } public String toBibTeX() { StringBuilder sb = new StringBuilder(); sb.append('@').append(type == null ? BibEntryType.MISC.getType() : type.getType()); sb.append('{').append(key == null ? generateKey() : key).append(",\n"); for (BibEntryFieldType field : fields.keySet()) { sb.append('\t').append(field.getType()).append(" = {"); List<String> values = new ArrayList<String>(); for (BibEntryField bef : fields.get(field)) { values.add(bef.getText()); } sb.append(escape(StringUtils.join(values, ", "))).append("},\n"); } sb.append('}'); return sb.toString(); } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final BibEntry other = (BibEntry) obj; if ((this.type == null) ? (other.type != null) : !this.type.equals(other.type)) { return false; } if ((this.key == null) ? (other.key != null) : !this.key.equals(other.key)) { return false; } if ((this.text == null) ? (other.text != null) : !this.text.equals(other.text)) { return false; } if (this.fields == other.fields) { return true; } return this.fields != null && this.fields.equals(other.fields); } @Override public int hashCode() { int hash = 3; hash = 23 * hash + (this.type != null ? this.type.hashCode() : 0); hash = 23 * hash + (this.key != null ? this.key.hashCode() : 0); hash = 23 * hash + (this.text != null ? this.text.hashCode() : 0); hash = 23 * hash + (this.fields != null ? this.fields.hashCode() : 0); return hash; } }
7,389
30.05042
97
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/transformers/BibEntryToBibTeXWriter.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.bibref.transformers; import java.io.IOException; import java.io.Writer; import java.util.List; import pl.edu.icm.cermine.bibref.model.BibEntry; import pl.edu.icm.cermine.exception.TransformationException; import pl.edu.icm.cermine.tools.transformers.ModelToFormatWriter; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class BibEntryToBibTeXWriter implements ModelToFormatWriter<BibEntry> { @Override public String write(BibEntry object, Object... hints) throws TransformationException { return object.toBibTeX(); } @Override public void write(Writer writer, BibEntry object, Object... hints) throws TransformationException { try { writer.write(write(object, hints)); } catch (IOException e) { throw new TransformationException(e); } } @Override public String writeAll(List<BibEntry> objects, Object... hints) throws TransformationException { StringBuilder sb = new StringBuilder(); for (BibEntry entry : objects) { sb.append(entry.toBibTeX()); sb.append("\n\n"); } return sb.toString().trim(); } @Override public void writeAll(Writer writer, List<BibEntry> objects, Object... hints) throws TransformationException { try { writer.write(writeAll(objects, hints)); } catch (IOException e) { throw new TransformationException(e); } } }
2,228
33.292308
113
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/transformers/NLMToBibEntryConverter.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.bibref.transformers; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.jdom.Element; import org.jdom.Text; import pl.edu.icm.cermine.bibref.model.BibEntry; import pl.edu.icm.cermine.bibref.model.BibEntryFieldType; import pl.edu.icm.cermine.bibref.model.BibEntryType; import pl.edu.icm.cermine.exception.TransformationException; import pl.edu.icm.cermine.tools.transformers.ModelToModelConverter; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class NLMToBibEntryConverter implements ModelToModelConverter<Element, BibEntry> { private static final Map<String, BibEntryFieldType> NLM_TO_BIBENTRY = new HashMap<String, BibEntryFieldType>(); static { NLM_TO_BIBENTRY.put("article-title", BibEntryFieldType.TITLE); NLM_TO_BIBENTRY.put("named-content", BibEntryFieldType.CONTENTS); NLM_TO_BIBENTRY.put("edition", BibEntryFieldType.EDITION); NLM_TO_BIBENTRY.put("publisher-name", BibEntryFieldType.PUBLISHER); NLM_TO_BIBENTRY.put("publisher-loc", BibEntryFieldType.LOCATION); NLM_TO_BIBENTRY.put("series", BibEntryFieldType.SERIES); NLM_TO_BIBENTRY.put("source", BibEntryFieldType.JOURNAL); NLM_TO_BIBENTRY.put("uri", BibEntryFieldType.URL); NLM_TO_BIBENTRY.put("volume", BibEntryFieldType.VOLUME); NLM_TO_BIBENTRY.put("year", BibEntryFieldType.YEAR); NLM_TO_BIBENTRY.put("issue", BibEntryFieldType.NUMBER); } @Override public BibEntry convert(Element source, Object... hints) throws TransformationException { BibEntry bibEntry = new BibEntry(BibEntryType.ARTICLE); String text = source.getValue().trim().replaceAll("\\s+", " "); bibEntry.setText(text); Map<Element, Integer> fIndex = new HashMap<Element, Integer>(); Map<Element, Integer> lIndex = new HashMap<Element, Integer>(); List content = source.getContent(); int index = 0; for (Object child : content) { if (child instanceof Text) { String chText = ((Text) child).getTextNormalize(); int oldLength = text.length(); text = text.substring(chText.length()).trim(); index += (oldLength - text.length()); } else if (child instanceof Element) { Element elChild = (Element) child; fIndex.put(elChild, index); String chText = elChild.getValue().trim().replaceAll("\\s+", " "); lIndex.put(elChild, index + chText.length()); int oldLength = text.length(); text = text.substring(chText.length()).trim(); index += (oldLength - text.length()); } else { throw new TransformationException("Unknown element class found: "+child.getClass().getName()); } } List children = source.getChildren(); for (int i = 0; i < children.size(); i++) { Element child = (Element) children.get(i); if (NLM_TO_BIBENTRY.containsKey(child.getName())) { bibEntry.addField(NLM_TO_BIBENTRY.get(child.getName()), child.getTextNormalize(), fIndex.get(child), lIndex.get(child)); } else if ("pub-id".equals(child.getName())) { if ("doi".equals(child.getAttributeValue("pub-id-type"))) { bibEntry.addField(BibEntryFieldType.DOI, child.getTextNormalize(), fIndex.get(child), lIndex.get(child)); } else if ("pmid".equals(child.getAttributeValue("pub-id-type"))) { bibEntry.addField(BibEntryFieldType.PMID, child.getTextNormalize(), fIndex.get(child), lIndex.get(child)); } } else if ("fpage".equals(child.getName())) { String pages = child.getText(); int lastIndex = lIndex.get(child); if (i + 1 < children.size()) { Element nextChild = (Element) children.get(i+1); if ("lpage".equals(nextChild.getName())) { pages += "--"; pages += nextChild.getText(); lastIndex = lIndex.get(nextChild); } } bibEntry.addField(BibEntryFieldType.PAGES, pages, fIndex.get(child), lastIndex); } else if ("string-name".equals(child.getName())) { String name = child.getValue().trim().replaceAll("\\s+", " "); if (child.getChild("surname") != null) { name = child.getChildTextNormalize("surname"); if (child.getChild("given-names") != null) { name += ", "; name += child.getChildTextNormalize("given-names"); } } bibEntry.addField(BibEntryFieldType.AUTHOR, name, fIndex.get(child), lIndex.get(child)); } } return bibEntry; } @Override public List<BibEntry> convertAll(List<Element> source, Object... hints) throws TransformationException { List<BibEntry> entries = new ArrayList<BibEntry>(source.size()); for (Element element : source) { entries.add(convert(element, hints)); } return entries; } }
6,243
45.597015
136
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/transformers/BibEntryToNLMConverter.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.bibref.transformers; import java.util.*; import org.jdom.Element; import pl.edu.icm.cermine.bibref.model.BibEntry; import pl.edu.icm.cermine.bibref.model.BibEntryField; import pl.edu.icm.cermine.bibref.model.BibEntryFieldType; import pl.edu.icm.cermine.exception.TransformationException; import pl.edu.icm.cermine.tools.XMLTools; import pl.edu.icm.cermine.tools.transformers.ModelToModelConverter; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class BibEntryToNLMConverter implements ModelToModelConverter<BibEntry, Element> { private static final Map<BibEntryFieldType, String> BIBENTRY_TO_NLM = new EnumMap<BibEntryFieldType, String>(BibEntryFieldType.class); static { BIBENTRY_TO_NLM.put(BibEntryFieldType.TITLE, "article-title"); BIBENTRY_TO_NLM.put(BibEntryFieldType.CONTENTS, "named-content"); BIBENTRY_TO_NLM.put(BibEntryFieldType.EDITION, "edition"); BIBENTRY_TO_NLM.put(BibEntryFieldType.PUBLISHER, "publisher-name"); BIBENTRY_TO_NLM.put(BibEntryFieldType.LOCATION, "publisher-loc"); BIBENTRY_TO_NLM.put(BibEntryFieldType.SERIES, "series"); BIBENTRY_TO_NLM.put(BibEntryFieldType.JOURNAL, "source"); BIBENTRY_TO_NLM.put(BibEntryFieldType.URL, "uri"); BIBENTRY_TO_NLM.put(BibEntryFieldType.VOLUME, "volume"); BIBENTRY_TO_NLM.put(BibEntryFieldType.YEAR, "year"); BIBENTRY_TO_NLM.put(BibEntryFieldType.NUMBER, "issue"); BIBENTRY_TO_NLM.put(BibEntryFieldType.INSTITUTION, "institution"); } @Override public Element convert(BibEntry entry, Object... hints) throws TransformationException { Element element = new Element("mixed-citation"); Map<BibEntryField, BibEntryFieldType> fieldKeyMap = new HashMap<BibEntryField, BibEntryFieldType>(); String text = entry.getText(); List<BibEntryField> fields = new ArrayList<BibEntryField>(); for (BibEntryFieldType key : entry.getFieldKeys()) { fields.addAll(entry.getAllFields(key)); for (BibEntryField field : entry.getAllFields(key)) { fieldKeyMap.put(field, key); } } Collections.sort(fields, new Comparator<BibEntryField>() { @Override public int compare(BibEntryField t1, BibEntryField t2) { return Integer.valueOf(t1.getStartIndex()).compareTo(t2.getStartIndex()); } }); int lastIndex = 0; for (BibEntryField field : fields) { if (field.getStartIndex() < 0) { continue; } String fieldText = text.substring(field.getStartIndex(), field.getEndIndex()); if (field.getStartIndex() != lastIndex) { element.addContent(XMLTools.removeInvalidXMLChars(text.substring(lastIndex, field.getStartIndex()))); } if (BIBENTRY_TO_NLM.get(fieldKeyMap.get(field)) != null) { Element fieldElement = new Element(BIBENTRY_TO_NLM.get(fieldKeyMap.get(field))); fieldElement.setText(XMLTools.removeInvalidXMLChars(fieldText)); element.addContent(fieldElement); } else if (BibEntryFieldType.DOI.equals(fieldKeyMap.get(field))) { Element doiElement = new Element("pub-id"); doiElement.setText(XMLTools.removeInvalidXMLChars(fieldText)); doiElement.setAttribute("pub-id-type", "doi"); element.addContent(doiElement); } else if (BibEntryFieldType.PMID.equals(fieldKeyMap.get(field))) { Element doiElement = new Element("pub-id"); doiElement.setText(XMLTools.removeInvalidXMLChars(fieldText)); doiElement.setAttribute("pub-id-type", "pmid"); element.addContent(doiElement); } else if (BibEntryFieldType.PAGES.equals(fieldKeyMap.get(field))) { if (!field.getText().contains("--")) { Element firstPageElement = new Element("fpage"); firstPageElement.setText(XMLTools.removeInvalidXMLChars(field.getText())); element.addContent(firstPageElement); } else { String firstPage = field.getText().replaceAll("--.*", ""); String lastPage = field.getText().replaceAll(".*--", ""); int firstPageIndex = fieldText.indexOf(firstPage); int lastPageIndex = fieldText.indexOf(lastPage, firstPageIndex + firstPage.length()); element.addContent(XMLTools.removeInvalidXMLChars(fieldText.substring(0, firstPageIndex))); Element firstPageElement = new Element("fpage"); firstPageElement.setText(XMLTools.removeInvalidXMLChars(firstPage)); element.addContent(firstPageElement); element.addContent(XMLTools.removeInvalidXMLChars(fieldText.substring(firstPageIndex + firstPage.length(), lastPageIndex))); Element lastPageElement = new Element("lpage"); lastPageElement.setText(XMLTools.removeInvalidXMLChars(lastPage)); element.addContent(lastPageElement); } } else if (BibEntryFieldType.AUTHOR.equals(fieldKeyMap.get(field))) { if (!field.getText().contains(", ")) { Element nameElement = new Element("string-name"); Element firstElement = new Element("surname"); firstElement.setText(XMLTools.removeInvalidXMLChars(field.getText())); nameElement.addContent(firstElement); element.addContent(nameElement); } else { String surname = field.getText().replaceAll(", .*", ""); String givenname = field.getText().replaceAll(".*, ", ""); int surnameIndex = fieldText.indexOf(surname); int givennameIndex = fieldText.indexOf(givenname, surnameIndex + surname.length()); if (givennameIndex < 0) { givennameIndex = fieldText.indexOf(givenname); surnameIndex = fieldText.indexOf(surname, givennameIndex + givenname.length()); } String firstText = surname; String firstLabel = "surname"; int firstIndex = surnameIndex; String secondText = givenname; String secondLabel = "given-names"; int secondIndex = givennameIndex; if (secondIndex < firstIndex) { firstText = givenname; firstLabel = "given-names"; firstIndex = givennameIndex; secondText = surname; secondLabel = "surname"; secondIndex = surnameIndex; } Element nameElement = new Element("string-name"); nameElement.addContent(XMLTools.removeInvalidXMLChars(fieldText.substring(0, firstIndex))); Element firstElement = new Element(firstLabel); firstElement.setText(XMLTools.removeInvalidXMLChars(firstText)); nameElement.addContent(firstElement); nameElement.addContent(XMLTools.removeInvalidXMLChars(fieldText.substring(firstIndex + firstText.length(), secondIndex))); Element lastElement = new Element(secondLabel); lastElement.setText(XMLTools.removeInvalidXMLChars(secondText)); nameElement.addContent(lastElement); nameElement.addContent(XMLTools.removeInvalidXMLChars(fieldText.substring(secondIndex + secondText.length(), fieldText.length()))); element.addContent(nameElement); } } lastIndex = field.getEndIndex(); } if (lastIndex < text.length()) { element.addContent(XMLTools.removeInvalidXMLChars(text.substring(lastIndex, text.length()))); } return element; } @Override public List<Element> convertAll(List<BibEntry> source, Object... hints) throws TransformationException { List<Element> elements = new ArrayList<Element>(source.size()); for (BibEntry entry: source) { elements.add(convert(entry, hints)); } return elements; } }
9,685
48.167513
151
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/transformers/BibTeXToBibEntryReader.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.bibref.transformers; import java.io.IOException; import java.io.Reader; import java.util.ArrayList; import java.util.List; import java.util.Locale; import org.apache.commons.io.IOUtils; import pl.edu.icm.cermine.bibref.model.BibEntry; import pl.edu.icm.cermine.bibref.model.BibEntryFieldType; import pl.edu.icm.cermine.bibref.model.BibEntryType; import pl.edu.icm.cermine.exception.TransformationException; import pl.edu.icm.cermine.tools.transformers.FormatToModelReader; /** * Reader of BibTeX format to BibEntry model. * * @author Ewa Stocka * @author Lukasz Bolikowski (bolo@icm.edu.pl) * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class BibTeXToBibEntryReader implements FormatToModelReader<BibEntry> { @Override public BibEntry read(String string, Object... hints) throws TransformationException { return processBibteX(string); } @Override public BibEntry read(Reader reader, Object... hints) throws TransformationException { try { return processBibteX(IOUtils.toString(reader)); } catch (IOException ex) { throw new TransformationException(ex); } } @Override public List<BibEntry> readAll(String string, Object... hints) throws TransformationException { List<BibEntry> entries = new ArrayList<BibEntry>(); String[] split = string.split("\n\n"); for (String s : split) { entries.add(processBibteX(s.substring(s.indexOf('@')))); } return entries; } @Override public List<BibEntry> readAll(Reader reader, Object... hints) throws TransformationException { try { return readAll(IOUtils.toString(reader)); } catch (IOException ex) { throw new TransformationException(ex); } } protected BibEntry processBibteX(String bibteX) throws TransformationException { BibEntry bibEntry = new BibEntry(); String[] lines = bibteX.split("\n"); //type int indexOfAt = lines[0].indexOf('@'); if (indexOfAt < 0) { throw new TransformationException("Cannot parse string as BibTeX!"); } int indexOfBrace = lines[0].indexOf('{'); if (indexOfBrace < 0) { throw new TransformationException("Cannot parse string as BibTeX!"); } if (indexOfBrace > indexOfAt) { String type = lines[0].substring(indexOfAt + 1, indexOfBrace).toLowerCase(Locale.ENGLISH); //list?? bibEntry.setType(BibEntryType.ofType(type)); } else { throw new TransformationException("Cannot parse string as BibTeX!"); } //fields for (int i = 1; i < lines.length; i++) { if (lines[i].matches("\\s\\w*\\s*=\\s*[{].*[},]")) { String[] field = lines[i].split("\\s*=\\s*[{]"); String key = field[0].trim().toLowerCase(Locale.ENGLISH); String value = field[1].substring(0, field[1].length() - 2); String[] values = value.split(","); if (key.equals(BibEntryFieldType.AUTHOR.getType())) { for (int j = 0; j < values.length; j+=2) { String val = values[j]; if (j + 1 < values.length) { val += ","; val += values[j+1]; } bibEntry.addField(BibEntryFieldType.AUTHOR, revertEscape(val)); } } else { for (String val : values) { bibEntry.addField(BibEntryFieldType.ofType(key), revertEscape(val)); } } } } return bibEntry; } protected String revertEscape(String text) { return text.trim().replace("\\{", "{").replace("\\}", "}").replace("\\_", "_"); } }
4,712
35.253846
102
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/model/Document.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.model; import java.util.List; import pl.edu.icm.cermine.bibref.model.BibEntry; import pl.edu.icm.cermine.content.model.ContentStructure; import pl.edu.icm.cermine.metadata.model.DocumentMetadata; /** * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) */ public class Document { private DocumentMetadata metadata; private ContentStructure content; private List<BibEntry> references; public DocumentMetadata getMetadata() { return metadata; } public void setMetadata(DocumentMetadata metadata) { this.metadata = metadata; } public ContentStructure getContent() { return content; } public void setContent(ContentStructure content) { this.content = content; } public List<BibEntry> getReferences() { return references; } public void setReferences(List<BibEntry> references) { this.references = references; } }
1,693
27.233333
78
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/EnhancerMetadataExtractor.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; import java.util.Arrays; 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.extraction.enhancers.*; import pl.edu.icm.cermine.metadata.model.DocumentMetadata; import pl.edu.icm.cermine.structure.model.BxDocument; import pl.edu.icm.cermine.tools.timeout.TimeoutRegister; /** * Extracting metadata from labelled zones. * * @author Krzysztof Rusek */ public class EnhancerMetadataExtractor implements MetadataExtractor<DocumentMetadata> { private final List<Enhancer> enhancers = Arrays.<Enhancer>asList( new TitleAuthorSplitterEnhancer(), new AuthorTitleSplitterEnhancer(), new AuthorAffiliationSplitterEnhancer(), new AffiliationAuthorSplitterEnhancer(), new AuthorAffiliationGeometricEnhancer(), new HindawiCornerInfoEnhancer(), new TitleMergedWithTypeEnhancer(), new TitleEnhancer(), new AuthorEnhancer(), new EmailEnhancer(), new DoiEnhancer(), new UrnEnhancer(), new DescriptionEnhancer(), new KeywordsEnhancer(), new ArticleIdEnhancer(), new VolumeEnhancer(), new IssueEnhancer(), new JournalVolumeIssueWithAuthorEnhancer(), new JournalVolumeIssueEnhancer(), new JournalWithoutVolumeIssueEnhancer(), new JournalYearVolumeEnhancer(), new JournalVolumePagesYearEnhancer(), new JournalVolumePagesEnhancer(), new JournalVolumeIssueExtendedEnhancer(), new JournalIssnEnhancer(), new JournalEnhancer(), new IssnEnhancer(), new EditorEnhancer(), new AffiliationGeometricEnhancer(), new ReceivedDateEnhancer(), new AcceptedDateEnhancer(), new PublishedDateEnhancer(), new RevisedDateEnhancer(), new RevisedFormDateEnhancer(), new PagesEnhancer(), new PagesPartialEnhancer(), new PagesNumbersEnhancer(), new PagesLastEnhancer(), new CiteAsEnhancer(), new YearEnhancer() ); public List<Enhancer> getEnhancers() { return enhancers; } public EnhancerMetadataExtractor addEnhancer(Enhancer enhancer) { enhancers.add(enhancer); return this; } public EnhancerMetadataExtractor setEnhancers(List<Enhancer> value) { enhancers.clear(); enhancers.addAll(value); return this; } @Override public DocumentMetadata extractMetadata(BxDocument document) throws AnalysisException { Set<EnhancedField> enhancedFields = EnumSet.noneOf(EnhancedField.class); DocumentMetadata metadata = new DocumentMetadata(); for (Enhancer enhancer : enhancers) { enhancer.enhanceMetadata(document, metadata, enhancedFields); TimeoutRegister.get().check(); } metadata.clean(); return metadata; } }
4,088
35.837838
91
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/MetadataExtractor.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; import pl.edu.icm.cermine.exception.AnalysisException; import pl.edu.icm.cermine.structure.model.BxDocument; /** * Interface for extracting metadata from labelled zones. * * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl) * @param <T> a type of metadata objects */ public interface MetadataExtractor<T> { /** * Extracts metadata from the document. * * @param document document * @return extracted metadata * @throws AnalysisException AnalysisException */ T extractMetadata(BxDocument document) throws AnalysisException; }
1,341
32.55
78
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/EmailEnhancer.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.Locale; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.lang.StringUtils; import pl.edu.icm.cermine.metadata.model.DocumentAuthor; 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 class EmailEnhancer extends AbstractSimpleEnhancer { private static final String NAME_REGEXP = "[\\w!\\+\\-\\.]+"; private static final String NAME_MULTI_REGEXP = "[\\w!\\+\\-\\.\\|, ]+"; private static final String DOMAIN_REGEXP = "[\\w\\-\\.]+"; private static final Pattern PATTERN = Pattern.compile(NAME_REGEXP + "@" + DOMAIN_REGEXP); private static final Pattern MULTI_PATTERN = Pattern.compile("[\\{\\[\\(](" + NAME_MULTI_REGEXP + ")[\\}\\]\\)]@(" + DOMAIN_REGEXP + ")"); public EmailEnhancer() { this.setSearchedZoneLabels(BxZoneLabel.MET_CORRESPONDENCE, BxZoneLabel.MET_AFFILIATION); } @Override protected Set<EnhancedField> getEnhancedFields() { return EnumSet.of(EnhancedField.EMAIL); } @Override protected boolean enhanceMetadata(BxZone zone, DocumentMetadata metadata) { Matcher matcher = MULTI_PATTERN.matcher(zone.toText()); while (matcher.find()) { String emails = matcher.group(1); String domain = matcher.group(2); String[] names = emails.split("[\\|, ]+"); for (String name : names) { if (!name.isEmpty()) { addEmail(metadata, name+"@"+domain); } } } matcher = PATTERN.matcher(zone.toText()); while (matcher.find()) { String email = matcher.group().replaceFirst("[;\\.,]$", ""); if (!email.contains("}")) { addEmail(metadata, email.replaceFirst("^\\(", "").replaceFirst("\\)$", "")); } } return false; } private void addEmail(DocumentMetadata metadata, String email) { DocumentAuthor author = null; boolean one = true; for (DocumentAuthor a : metadata.getAuthors()) { String[] names = a.getName().split(" "); String fname = StringUtils.join(names, ""); if (fname.toLowerCase(Locale.ENGLISH).contains(email.toLowerCase(Locale.ENGLISH).replaceFirst("@.*", ""))) { if (author == null) { author = a; break; } else { one = false; } } else { for (String namePart : names) { if (namePart.length() > 2 && email.toLowerCase(Locale.ENGLISH).contains(namePart.toLowerCase(Locale.ENGLISH))) { if (author == null) { author = a; break; } else { one = false; } } } } } if (author != null && one) { author.addEmail(email); } } }
4,062
36.275229
142
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/IssnEnhancer.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 Krzysztof Rusek */ public class IssnEnhancer extends AbstractPatternEnhancer { private static final Pattern PATTERN = Pattern.compile( "\\bISSN:?\\s*(\\d{4}[" + String.valueOf(CharacterUtils.DASH_CHARS) + "]\\d{3}[\\dX])\\b", Pattern.CASE_INSENSITIVE); private static final Set<BxZoneLabel> SEARCHED_ZONE_LABELS = EnumSet.of(BxZoneLabel.MET_BIB_INFO); public IssnEnhancer() { super(PATTERN, SEARCHED_ZONE_LABELS); } @Override protected Set<EnhancedField> getEnhancedFields() { return EnumSet.of(EnhancedField.ISSN); } @Override protected boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata) { metadata.setJournalISSN(result.group(1)); return true; } }
1,861
33.481481
102
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/ReceivedDateEnhancer.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 ReceivedDateEnhancer extends AbstractDateEnhancer { public ReceivedDateEnhancer() { super(EnhancedField.RECEIVED_DATE, "received"); } @Override protected void enhanceMetadata(DocumentMetadata metadata, String day, String month, String year) { metadata.setDate(DateType.RECEIVED, day, month, year); } }
1,295
33.105263
102
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/DoiEnhancer.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.metadata.model.IDType; import pl.edu.icm.cermine.structure.model.BxZoneLabel; import pl.edu.icm.cermine.tools.PatternUtils; /** * @author Krzysztof Rusek */ public class DoiEnhancer extends AbstractMultiPatternEnhancer { private static final List<Pattern> PATTERNS = Lists.newArrayList( Pattern.compile("\\bdoi:?\\s*(" + PatternUtils.DOI_PATTERN + ")", Pattern.CASE_INSENSITIVE), Pattern.compile("\\bdx\\.doi\\.org/(" + PatternUtils.DOI_PATTERN + ")", Pattern.CASE_INSENSITIVE) ); private static final Set<BxZoneLabel> SEARCHED_ZONE_LABELS = EnumSet.of(BxZoneLabel.MET_BIB_INFO); public DoiEnhancer() { super(PATTERNS, SEARCHED_ZONE_LABELS); } @Override protected Set<EnhancedField> getEnhancedFields() { return EnumSet.of(EnhancedField.DOI); } @Override protected boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata) { metadata.addId(IDType.DOI, result.group(1).replaceAll(",$", "")); return true; } }
2,100
35.224138
109
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/EditorEnhancer.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.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 class EditorEnhancer extends AbstractSimpleEnhancer { private static final Pattern PREFIX_PATTERN = Pattern.compile( "^\\s*(?:academic\\s*)?editor:", Pattern.CASE_INSENSITIVE); public EditorEnhancer() { setSearchedZoneLabels(BxZoneLabel.MET_EDITOR); } @Override protected Set<EnhancedField> getEnhancedFields() { return EnumSet.of(EnhancedField.EDITOR); } @Override protected boolean enhanceMetadata(BxZone zone, DocumentMetadata metadata) { String text = zone.toText(); Matcher matcher = PREFIX_PATTERN.matcher(text); if (matcher.find()) { text = text.substring(matcher.end()).trim(); } metadata.addEditor(text); return true; } }
1,894
31.672414
79
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/JournalIssnEnhancer.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 JournalIssnEnhancer extends AbstractPatternEnhancer { private static final Pattern PATTERN = Pattern.compile( "([A-Z][^0-9]+)\\s[Ii][Ss][Ss][Nn]:?\\s*(\\d{4}[" + String.valueOf(CharacterUtils.DASH_CHARS) + "]\\d{3}[\\dXx])\\b"); private static final Set<BxZoneLabel> SEARCHED_ZONE_LABELS = EnumSet.of(BxZoneLabel.MET_BIB_INFO); public JournalIssnEnhancer() { super(PATTERN, SEARCHED_ZONE_LABELS); } @Override protected Set<EnhancedField> getEnhancedFields() { return EnumSet.of(EnhancedField.JOURNAL, EnhancedField.ISSN); } @Override protected boolean enhanceMetadata(MatchResult result, DocumentMetadata metadata) { metadata.setJournal(result.group(1).trim() .replaceAll("Published as: ", "").replaceAll(",$", "")); metadata.setJournalISSN(result.group(2)); return true; } }
2,035
36.018182
130
java
CERMINE
CERMINE-master/cermine-impl/src/main/java/pl/edu/icm/cermine/metadata/extraction/enhancers/JournalVolumeIssueEnhancer.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 JournalVolumeIssueEnhancer 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 JournalVolumeIssueEnhancer() { super(PATTERNS, 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) { metadata.setJournal(result.group(1).trim() .replaceAll("Published as: ", "").replaceAll(",$", "") .replaceAll(".*/", "").trim()); metadata.setVolume(result.group(2)); metadata.setIssue(result.group(3)); return true; } }
2,350
36.31746
130
java