diff --git a/MibTeX/.classpath b/MibTeX/.classpath index 354c6a0..d44a750 100644 --- a/MibTeX/.classpath +++ b/MibTeX/.classpath @@ -4,6 +4,7 @@ + diff --git a/MibTeX/lib/ini4j-0.5.4.jar b/MibTeX/lib/ini4j-0.5.4.jar new file mode 100644 index 0000000..499f0af Binary files /dev/null and b/MibTeX/lib/ini4j-0.5.4.jar differ diff --git a/MibTeX/resources/index2_in.html b/MibTeX/resources/index2_in.html deleted file mode 100644 index d3521ec..0000000 --- a/MibTeX/resources/index2_in.html +++ /dev/null @@ -1,412 +0,0 @@ - - - - - MibTex - - - - - -
- - - - -
/
-
- - - - - - - - - - - - - - - - - - - - - DATA_INSERT_HERE - -
- Title - - Authors - - Venues - - Tags - - Citations - - Year -
- - INSERT_VENUE_OPTIONS - - - - INSERT_TAG_OPTIONS - - - - INSERT_YEAR_OPTIONS - -
- - \ No newline at end of file diff --git a/MibTeX/resources/index_in.html b/MibTeX/resources/index_in.html index 047d48e..18ea1dd 100644 --- a/MibTeX/resources/index_in.html +++ b/MibTeX/resources/index_in.html @@ -1,2885 +1,418 @@ - - - Mibtex - - - + + +
+ + + + +
/
+
+ + + + + + + + + + - - - + + + + + + + + + DATA_INSERT_HERE
+ Authors + + Title + + Venues + + Tags + + Citations + + Year +
- - - {{obj.name}} - - - {{obj.name}}, - {{obj.name}} - - - {{obj.name}} - - - {{obj.name}}, - {{obj.name}} - - -
+ + INSERT_VENUE_OPTIONS + + + + INSERT_TAG_OPTIONS + + + + INSERT_YEAR_OPTIONS + +
- - - - -
-Number of entries: {{gridData.length}} - - - - -
- - - + \ No newline at end of file diff --git a/MibTeX/src/de/mibtex/BibtexViewer.java b/MibTeX/src/de/mibtex/BibtexViewer.java index c28940f..46569a6 100644 --- a/MibTeX/src/de/mibtex/BibtexViewer.java +++ b/MibTeX/src/de/mibtex/BibtexViewer.java @@ -6,93 +6,142 @@ */ package de.mibtex; -import de.mibtex.export.Export; -import de.mibtex.export.ExportCSV; -import de.mibtex.export.ExportCitations; -import de.mibtex.export.ExportHTML; -import de.mibtex.export.ExportJSON; -import de.mibtex.export.ExportNewHTML2; +import de.mibtex.export.*; +import org.ini4j.Ini; +import org.ini4j.Wini; + +import java.io.File; +import java.io.IOException; /** * A class to export a given BibTeX file to another format - * + * * @author Thomas Thuem, Christopher Sontag */ public class BibtexViewer { - - public static String BIBTEX_DIR; - - public static String MAIN_DIR; - - public static String HTML_DIR; - - public static String PDF_DIR_REL; - - public static String PDF_DIR; - - public static String TAGS; - + + public static String BIBTEX_DIR = ""; + + public static String MAIN_DIR = ""; + + public static String OUTPUT_DIR = ""; + + public static String PDF_DIR_REL = ""; + + public static String PDF_DIR = ""; + + public static String TAGS = ""; + private static boolean cleanOutputDir; - + private static boolean updateCitations; - - public static String CITATION_DIR; - + + private static String format = "HTML"; + + public static String CITATION_DIR; + /** * Example arguments - * + *

* BibtexViewer "C:\\Users\\tthuem\\workspace4.2.1\\tthuem-Bibtex\\" * "C:\\Users\\tthuem\\Dropbox\\Literatur\\" "HTML\\" "..\\Library\\" - * "Library\\" "tt-tags" "CSV/JSON/HTML" "true" "C:\\Users\\tthuem\\workspace4.2.1\\tthuem-Bibtex\\" - * + * "Library\\" "tt-tags" "CSV/JSON/HTML/Classification" "true" "C:\\Users\\tthuem\\workspace4.2.1\\tthuem-Bibtex\\" + * * @param args array containing: - * - path to Bibtex file path to main directory - * - relative path of the HTML to main directory - * - relative path of PDF files to the HTML folder (for linking files in HTML) - * - relative path of PDF files to main directory - * - name of the tag containing your keywords - * - format for export (CSV/JSON/HTML) - * - boolean for output cleaning (default: false) - * - boolean for update citations file (default:true) - * - path to citations file (default: Bibtex file path) + * - path to Bibtex file path to main directory + * - relative path of the HTML to main directory + * - relative path of PDF files to the HTML folder (for linking files in HTML) + * - relative path of PDF files to main directory + * - name of the tag containing your keywords + * - format for export (CSV/JSON/HTML) + * - boolean for output cleaning (default: false) + * - boolean for update citations file (default:true) + * - path to citations file (default: Bibtex file path) */ public static void main(String[] args) { - BIBTEX_DIR = args[0]; - MAIN_DIR = args[1]; - HTML_DIR = MAIN_DIR + args[2]; - PDF_DIR_REL = args[3]; - PDF_DIR = MAIN_DIR + args[4]; - TAGS = args[5]; - try { - cleanOutputDir = Boolean.getBoolean(args[7]); - } catch (Exception e) { - System.out - .println("Output will not be cleaned"); - cleanOutputDir = false; - } - try { - updateCitations = Boolean.getBoolean(args[8]); - } catch (Exception e) { - System.out - .println("Citations are going to be updated"); - updateCitations = true; - } - try { - CITATION_DIR = args[9]; - } catch (Exception e) { - System.out - .println("Citation is saved in Bibtex directory"); - CITATION_DIR = BIBTEX_DIR; - } - String format = "HTML"; - try { - format = args[6]; - } catch (Exception e) { - System.out - .println("Exportformat Parameter not recognized. Setting Exportformat to HTML"); + if (args.length <= 1) { + String configurationFile; + if (args.length == 0) + configurationFile = "options.ini"; + else { + configurationFile = args[0]; + } + File iniFile = new File(configurationFile); + if (iniFile.exists()) { + Ini ini = null; + if (System.getProperty("os.name").contains("Windows")) { + try { + ini = new Wini(iniFile); + } catch (IOException e) { + e.printStackTrace(); + } + } else { + try { + ini = new Ini(iniFile); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (ini != null) { + BIBTEX_DIR = ini.get("options", "bibtex-dir"); + MAIN_DIR = ini.get("options", "main-dir"); + OUTPUT_DIR = MAIN_DIR + ini.get("options", "out-dir-rel"); + PDF_DIR = MAIN_DIR + ini.get("options", "pdf-dir"); + PDF_DIR_REL = ini.get("options", "pdf-dir-rel"); + TAGS = ini.get("options", "tags"); + cleanOutputDir = ini.get("options", "clean", Boolean.class); + updateCitations = ini.get("options", "citationService", Boolean.class); + String citationDir = ini.get("options", "citation-dir"); + if (citationDir == null || citationDir.isEmpty()) { + CITATION_DIR = BIBTEX_DIR; + } else { + CITATION_DIR = citationDir; + } + format = ini.get("options", "out-format"); + } else { + System.out.println("Ini file reader is null!"); + System.exit(0); + } + } else { + System.out.println("Options file not found under: " + iniFile.getName()); + } + } else { + BIBTEX_DIR = args[0]; + MAIN_DIR = args[1]; + OUTPUT_DIR = MAIN_DIR + args[2]; + PDF_DIR_REL = args[3]; + PDF_DIR = MAIN_DIR + args[4]; + TAGS = args[5]; + try { + cleanOutputDir = Boolean.getBoolean(args[7]); + } catch (Exception e) { + System.out + .println("Output will not be cleaned"); + cleanOutputDir = false; + } + try { + updateCitations = Boolean.getBoolean(args[8]); + } catch (Exception e) { + System.out + .println("Citations are going to be updated"); + updateCitations = true; + } + try { + CITATION_DIR = args[9]; + } catch (Exception e) { + System.out + .println("Citation is saved in Bibtex directory"); + CITATION_DIR = BIBTEX_DIR; + } + try { + format = args[6]; + } catch (Exception e) { + System.out + .println("Exportformat Parameter not recognized. Setting Exportformat to HTML"); + } } try { - if (updateCitations && format != "Citations") { + if (updateCitations && !"Citations".equals(format)) { new BibtexViewer("Citations"); } if (format != null) @@ -101,25 +150,28 @@ public static void main(String[] args) { e.printStackTrace(); } } - + public BibtexViewer(String format) throws Exception { Export exporter = null; switch (format) { case "CSV": - exporter = new ExportCSV(BibtexViewer.BIBTEX_DIR,"literature.bib"); + exporter = new ExportCSV(BibtexViewer.BIBTEX_DIR, "literature.bib"); break; case "JSON": - exporter = new ExportJSON(BibtexViewer.BIBTEX_DIR,"literature.bib"); + exporter = new ExportJSON(BibtexViewer.BIBTEX_DIR, "literature.bib"); break; case "Citations": - exporter = new ExportCitations(BibtexViewer.BIBTEX_DIR,"literature.bib"); + exporter = new ExportCitations(BibtexViewer.BIBTEX_DIR, "literature.bib"); + break; + case "Classification": + exporter = new ExportClassification(BibtexViewer.BIBTEX_DIR, "literature.bib"); break; case "HTML_NEW": - exporter = new ExportNewHTML2(BibtexViewer.BIBTEX_DIR,"literature.bib"); + exporter = new ExportNewHTML(BibtexViewer.BIBTEX_DIR, "literature.bib"); break; case "HTML": default: - exporter = new ExportHTML(BibtexViewer.BIBTEX_DIR,"literature.bib"); + exporter = new ExportHTML(BibtexViewer.BIBTEX_DIR, "literature.bib"); } if (cleanOutputDir) { exporter.cleanOutputFolder(); diff --git a/MibTeX/src/de/mibtex/citationservice/CitationService.java b/MibTeX/src/de/mibtex/citationservice/CitationService.java index a523f85..c47c96c 100644 --- a/MibTeX/src/de/mibtex/citationservice/CitationService.java +++ b/MibTeX/src/de/mibtex/citationservice/CitationService.java @@ -6,7 +6,11 @@ */ package de.mibtex.citationservice; +import org.ini4j.Ini; + import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; /** * A class to export the citations from scholar for each BibTeX entry @@ -15,20 +19,40 @@ */ public class CitationService { + private static String CITATION_DIR; + /** * Example arguments * * CitationService "C:\\Users\\tthuem\\workspace4.2.1\\tthuem-Bibtex\\" * - * @param arg + * @param args * containing path to the citations.csv (default: BibTeX dir) */ public static void main(String[] args) { + File iniFile = new File("options.ini"); + if (iniFile.exists()) { + Ini ini = null; + try { + ini = new Ini(iniFile); + } catch (IOException e) { + e.printStackTrace(); + } + String citationDir; + if (ini != null) { + citationDir = ini.get("options", "citation-dir"); + if (citationDir.isEmpty()) { + CITATION_DIR = ini.get("options", "bibtex-dir"); + } + } + } else { + CITATION_DIR = args[0]; + } try { - File file = new File(args[0], "citations.csv"); - ScholarService service = new ScholarService(file); - service.start(); - } catch (Exception e) { + File file = new File(CITATION_DIR, "citations.csv"); + ScholarService service = new ScholarService(file); + service.start(); + } catch (Exception e) { e.printStackTrace(); } } diff --git a/MibTeX/src/de/mibtex/citationservice/ScholarCitations.java b/MibTeX/src/de/mibtex/citationservice/ScholarCitations.java index 19e4447..8ce821f 100644 --- a/MibTeX/src/de/mibtex/citationservice/ScholarCitations.java +++ b/MibTeX/src/de/mibtex/citationservice/ScholarCitations.java @@ -18,64 +18,73 @@ /** * A class to read the number of citations from Google Scholar. - * + * * @author Thomas Thuem, Christopher Sontag */ public class ScholarCitations { - + private final static String SCHOLAR_URL = "http://scholar.google.com/scholar?q="; + private static Pattern entryPattern = Pattern.compile("

(.*?)Fewer<\\/a><\\/div><\\/div><\\/div>"); private static Pattern citationsPattern = Pattern - .compile("
.*?

(.*?)<\\/h3>.*?Cited by (\\d*).*?Save<\\/a>"); // OLD Pattern: "Cited by \\s*(\\d+)" - private static float levenshteinParameter = 0.7f; // This factor describes how much a title is allowed to change - // (Standart: Max. 70% of the original title) - - // public static int getYearlyCitations(String title, int publicationYear) { - // int citations = getCitations(title); - // if (citations < 0 || publicationYear < 1900) - // return citations; - // int currentYear = Calendar.getInstance().get(Calendar.YEAR); - // double passedYears = currentYear - publicationYear + 1; - // if (passedYears == 0) - // return citations; - // int average = (int) Math.round(citations / passedYears); - // return average; - // } - - public static int getCitations(String title) throws MalformedURLException, IOException { + .compile(".*?

(.*?)<\\/h3>.*?Cited by (\\d*).*?Fewer<\\/a><\\/div><\\/div><\\/div>"); + private static Pattern titlePattern = Pattern + .compile(".*?

(.*?)<\\/h3>"); + private static float levenshteinParameter = 10; // This factor describes how much a title is allowed to change (Standard: 10%) + + public static int getCitations(String title) throws IOException { String url = SCHOLAR_URL + title.replace(" ", "%20"); String html = toString(connect(new URL(url))); - Matcher matcher = citationsPattern.matcher(html.replace("\n", "")); - + Matcher entryMatcher = entryPattern.matcher(html.replace("\n", "")); + // Find minimal Distance between titles found and the original title - int bestElementCitations = 0; + int bestElementCitations = -1; int bestElementDistance = 99999; - - while (matcher.find()) { - String titleOutline = matcher.group(1); - int citations = Integer.parseInt(matcher.group(2)); - - // Remove HTML tags and annotations like [PDF], etc. - String titleFound = titleOutline.replaceAll("<.*?>", "").replaceAll("\\[.*\\]", "") - .replaceAll("%20", " ").trim(); - int elementDistance = Levenshtein.getDistance(titleFound, title); - - if (elementDistance < title.length() * levenshteinParameter) { - if (elementDistance < bestElementDistance) { - bestElementCitations = citations; - bestElementDistance = elementDistance; - } else if (elementDistance == bestElementDistance) { - if (citations > bestElementCitations) { + + while (entryMatcher.find()) { + Matcher citationsMatcher = citationsPattern.matcher(entryMatcher.group()); + if (citationsMatcher.find()) { + String titleOutline = citationsMatcher.group(1); + int citations = Integer.parseInt(citationsMatcher.group(2)); + + // Remove HTML tags and annotations like [PDF], etc. + String titleFound = titleOutline.replaceAll("<.*?>", "").replaceAll("\\[.*\\]", "") + .replaceAll("%20", " ").replaceAll("'", "'").trim(); + + int elementDistance = Levenshtein.getDistance(titleFound.toLowerCase(), title.toLowerCase()); + + if (elementDistance < (title.length() / 100.0f * levenshteinParameter)) { + if (elementDistance < bestElementDistance) { bestElementCitations = citations; bestElementDistance = elementDistance; + } else if (elementDistance == bestElementDistance) { + if (citations > bestElementCitations) { + bestElementCitations = citations; + bestElementDistance = elementDistance; + } + } + } + } else { + Matcher titleMatcher = titlePattern.matcher(entryMatcher.group()); + if (titleMatcher.find()) { + String titleOutline = titleMatcher.group(1); + String titleFound = titleOutline.replaceAll("<.*?>", "").replaceAll("\\[.*\\]", "") + .replaceAll("%20", " ").replaceAll("'", "'").trim(); + + int elementDistance = Levenshtein.getDistance(titleFound.toLowerCase(), title.toLowerCase()); + + if (elementDistance < (title.length() / 100.0f * levenshteinParameter) && elementDistance < bestElementDistance) { + bestElementCitations = 0; + bestElementDistance = elementDistance; } } } } - if (bestElementCitations > 0) + + if (bestElementCitations >= 0) return bestElementCitations; return CitationEntry.NOT_FOUND; } - + private static InputStream connect(URL url) throws IOException { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); String myCookie = "GSP=ID=bc97fd2103a97010:IN=88119b4bc736c413+eda666da4771d016:CF=4"; @@ -84,14 +93,14 @@ private static InputStream connect(URL url) throws IOException { "Mozilla/6.0 (Windows NT 5.1; en-US; rv:x.x.x) Gecko/20041109 Firefox/x.x"); return connection.getInputStream(); } - + private static String toString(InputStream in) throws IOException { StringBuffer out = new StringBuffer(); byte[] b = new byte[4096]; - for (int n; (n = in.read(b)) != -1;) { + for (int n; (n = in.read(b)) != -1; ) { out.append(new String(b, 0, n)); } return out.toString(); } - + } diff --git a/MibTeX/src/de/mibtex/export/Export.java b/MibTeX/src/de/mibtex/export/Export.java index 669cf42..14b2e30 100644 --- a/MibTeX/src/de/mibtex/export/Export.java +++ b/MibTeX/src/de/mibtex/export/Export.java @@ -38,266 +38,272 @@ /** * A abstract class that implements often used methods for the exporters - * + * * @author Thomas Thuem */ public abstract class Export { - protected static LinkedHashMap entries; + protected static LinkedHashMap entries; - protected static List authors; + protected static List authors; - protected static List titles; + protected static List titles; - protected static List years; + protected static List years; - protected static List venues; + protected static List venues; - protected static List tags; + protected static List tags; - public Export(String path, String file) throws Exception { - Reader reader = null; - try { - reader = new FileReader(new File(path + file)); - BibTeXParser parser = new BibTeXParser() { - @Override - public void checkStringResolution(Key key, BibTeXString string) { - } + public Export(String path, String file) throws Exception { + Reader reader = null; + try { + reader = new FileReader(new File(path + file)); + BibTeXParser parser = new BibTeXParser() { + @Override + public void checkStringResolution(Key key, BibTeXString string) { + } - @Override - public void checkCrossReferenceResolution(Key key, - BibTeXEntry entry) { - } - }; - BibTeXDatabase database = parser.parse(reader); - extractEntries(database); - } catch (FileNotFoundException e) { - System.out.println("BibTeX-File not found under " + file); - } catch (IOException e) { - System.out.println("BibTeXParser has an IOExeption"); - } catch (ParseException e) { - System.out.println("BibTeX-File cannot be parsed"); - } finally { - reader.close(); - } - readAuthors(); - readTitles(); - readYears(); - readVenues(); - readTags(); - } + @Override + public void checkCrossReferenceResolution(Key key, + BibTeXEntry entry) { + } + }; + BibTeXDatabase database = parser.parse(reader); + extractEntries(database); + } catch (FileNotFoundException e) { + System.out.println("BibTeX-File not found under " + path + file); + System.exit(0); + } catch (IOException e) { + System.out.println("BibTeXParser has an IOExeption"); + System.exit(0); + } catch (ParseException e) { + System.out.println("BibTeX-File cannot be parsed"); + System.exit(0); + } finally { + reader.close(); + } + readAuthors(); + readTitles(); + readYears(); + readVenues(); + readTags(); + } - private void extractEntries(BibTeXDatabase database) { - entries = new LinkedHashMap(); - for (BibTeXObject object : database.getObjects()) { - if (object instanceof BibTeXEntry) { - BibtexEntry bibtexEntry = new BibtexEntry((BibTeXEntry) object); - if (!entries.containsKey(bibtexEntry.key)) { - entries.put(bibtexEntry.key, bibtexEntry); - } else { - System.out.println("Found duplicate key: " - + bibtexEntry.key); - } - } - } - readCitations(); - } + private void extractEntries(BibTeXDatabase database) { + entries = new LinkedHashMap(); + for (BibTeXObject object : database.getObjects()) { + if (object instanceof BibTeXEntry) { + BibtexEntry bibtexEntry = new BibtexEntry((BibTeXEntry) object); + if (!entries.containsKey(bibtexEntry.key)) { + entries.put(bibtexEntry.key, bibtexEntry); + } else { + System.out.println("Found duplicate key: " + + bibtexEntry.key); + } + } + } + readCitations(); + } - private void readCitations() { - List citationsEntries = new ArrayList(); - File fileHandle = new File(BibtexViewer.CITATION_DIR, "citations.csv"); - if (fileHandle.exists()) { - try (BufferedReader br = new BufferedReader(new FileReader( - fileHandle))) { - for (String line; (line = br.readLine()) != null;) { - citationsEntries.add(CitationEntry.getFromCSV(line)); - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - for (CitationEntry citationEntry : citationsEntries) { - if (entries.containsKey(citationEntry.getKey())) { - BibtexEntry bibtexEntry = entries.get(citationEntry - .getKey()); - bibtexEntry.citations = citationEntry.getCitations(); - bibtexEntry.lastUpdate = citationEntry.getLastUpdate(); - } - } - } + private void readCitations() { + List citationsEntries = new ArrayList(); + File fileHandle = new File(BibtexViewer.CITATION_DIR, "citations.csv"); + if (fileHandle.exists()) { + try (BufferedReader br = new BufferedReader(new FileReader( + fileHandle))) { + for (String line; (line = br.readLine()) != null; ) { + citationsEntries.add(CitationEntry.getFromCSV(line)); + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + for (CitationEntry citationEntry : citationsEntries) { + if (entries.containsKey(citationEntry.getKey())) { + BibtexEntry bibtexEntry = entries.get(citationEntry + .getKey()); + bibtexEntry.citations = citationEntry.getCitations(); + bibtexEntry.lastUpdate = citationEntry.getLastUpdate(); + } + } + } - } + } - private void readAuthors() { - authors = new ArrayList(); - for (BibtexEntry entry : entries.values()) - for (String author : entry.authorList) - if (!authors.contains(author)) - authors.add(author); - Collections.sort(authors); - } + private void readAuthors() { + authors = new ArrayList(); + for (BibtexEntry entry : entries.values()) + for (String author : entry.authorList) + if (!authors.contains(author)) + authors.add(author); + Collections.sort(authors); + } - private void readTitles() { - titles = new ArrayList(); - for (BibtexEntry entry : entries.values()) - titles.add(entry.title); - Collections.sort(titles); - } + private void readTitles() { + titles = new ArrayList(); + for (BibtexEntry entry : entries.values()) + titles.add(entry.title); + Collections.sort(titles); + } - private void readYears() { - years = new ArrayList(); - for (BibtexEntry entry : entries.values()) - if (!years.contains(entry.year)) - years.add(entry.year); - Collections.sort(years); - } + private void readYears() { + years = new ArrayList(); + for (BibtexEntry entry : entries.values()) + if (!years.contains(entry.year)) + years.add(entry.year); + Collections.sort(years); + } - private void readVenues() { - venues = new ArrayList(); - for (BibtexEntry entry : entries.values()) - if (!venues.contains(entry.venue)) - venues.add(entry.venue); - Collections.sort(venues); - } + private void readVenues() { + venues = new ArrayList(); + for (BibtexEntry entry : entries.values()) + if (!venues.contains(entry.venue)) + venues.add(entry.venue); + Collections.sort(venues); + } - private void readTags() { - tags = new ArrayList(); - for (BibtexEntry entry : entries.values()) - for (String tag : entry.tagList) - if (!tags.contains(tag)) - tags.add(tag); - Collections.sort(tags); - } + private void readTags() { + tags = new ArrayList(); + for (BibtexEntry entry : entries.values()) + for (String tag : entry.tagList) + if (!tags.contains(tag)) + tags.add(tag); + Collections.sort(tags); + } - public void printMissingPDFs() { - for (BibtexEntry entry : entries.values()) { - File file = entry.getPDFPath(); - if (!file.exists()) - System.out.println(file.getName()); - } - } + public void printMissingPDFs() { + for (BibtexEntry entry : entries.values()) { + File file = entry.getPDFPath(); + if (!file.exists()) + System.out.println(file.getName()); + } + } - public void renameFiles() { - List available = new ArrayList(); - List missing = new ArrayList(); - try { - for (File file : new File(BibtexViewer.PDF_DIR).listFiles()) - available.add(file); - } catch (NullPointerException e) { - System.out.println("No PDFs in " + BibtexViewer.PDF_DIR); - } - for (BibtexEntry entry : entries.values()) { - File file = entry.getPDFPath(); - if (file.exists()) { - if (!available.remove(file)) - System.err.println("File comparison failed: " + file); - } else { - if (!"misc book".contains(entry.entry.getType().getValue())) - missing.add(entry); - } - } - System.out.println("Correct = " + (entries.size() - missing.size()) - + ", Available = " + available.size() + ", Missing = " - + missing.size()); - System.out.println(); - Scanner answer = new Scanner(System.in); - while (!available.isEmpty()) { - int minDistance = Integer.MAX_VALUE; - BibtexEntry missingEntry = null; - File availableFile = null; - for (BibtexEntry entry : missing) { - for (File file : available) { - int distance = Levenshtein.getDistance(file.getName(), - entry.getPDFPath().getName()); - if (distance < minDistance) { - minDistance = distance; - missingEntry = entry; - availableFile = file; - } - } - } - // stop if names are too different from each other - if (minDistance > availableFile.getName().length() * 0.7) - break; - if (availableFile != null) { - System.out.println("Available: " + availableFile.getName()); - System.out.println("Missing: " - + missingEntry.getPDFPath().getName()); - System.out.println("Key: " - + missingEntry.entry.getKey().getValue()); - System.out.println("Distance: " + minDistance); - System.out.println("Remaining: " + missing.size()); - if (answer.next().equals("y")) { - if (availableFile.renameTo(missingEntry.getPDFPath())) - available.remove(availableFile); - else - System.err.println("Renaming from \"" - + availableFile.getAbsolutePath() + "\" to \"" - + missingEntry.getPDFPath() - + "\" did not succeed!"); - } - missing.remove(missingEntry); - } - } - answer.close(); - System.out.println(); - for (File file : available) { - if (!file.getName().startsWith("0")) - file.renameTo(new File(file.getParentFile(), "0" - + file.getName())); - System.out.println("Available: " + file.getName()); - } - } + public void renameFiles() { + List available = new ArrayList(); + List missing = new ArrayList(); + try { + for (File file : new File(BibtexViewer.PDF_DIR).listFiles()) + available.add(file); + } catch (NullPointerException e) { + System.out.println("No PDFs in " + BibtexViewer.PDF_DIR); + } + for (BibtexEntry entry : entries.values()) { + File file = entry.getPDFPath(); + if (file.exists()) { + if (!available.remove(file)) + System.err.println("File comparison failed: " + file); + } else { + if (!"misc book".contains(entry.entry.getType().getValue())) + missing.add(entry); + } + } + System.out.println("Correct = " + (entries.size() - missing.size()) + + ", Available = " + available.size() + ", Missing = " + + missing.size()); + System.out.println(); + Scanner answer = new Scanner(System.in); + while (!available.isEmpty()) { + int minDistance = Integer.MAX_VALUE; + BibtexEntry missingEntry = null; + File availableFile = null; + for (BibtexEntry entry : missing) { + for (File file : available) { + int distance = Levenshtein.getDistance(file.getName(), + entry.getPDFPath().getName()); + if (distance < minDistance) { + minDistance = distance; + missingEntry = entry; + availableFile = file; + } + } + } + // stop if names are too different from each other + if (minDistance > availableFile.getName().length() * 0.7) + break; + if (availableFile != null) { + System.out.println("Available: " + availableFile.getName()); + System.out.println("Missing: " + + missingEntry.getPDFPath().getName()); + System.out.println("Key: " + + missingEntry.entry.getKey().getValue()); + System.out.println("Distance: " + minDistance); + System.out.println("Remaining: " + missing.size()); + if (answer.next().equals("y")) { + if (availableFile.renameTo(missingEntry.getPDFPath())) + available.remove(availableFile); + else + System.err.println("Renaming from \"" + + availableFile.getAbsolutePath() + "\" to \"" + + missingEntry.getPDFPath() + + "\" did not succeed!"); + } + missing.remove(missingEntry); + } + } + answer.close(); + System.out.println(); + for (File file : available) { + if (!file.getName().startsWith("0")) + file.renameTo(new File(file.getParentFile(), "0" + + file.getName())); + System.out.println("Available: " + file.getName()); + } + } - public void cleanOutputFolder() { - for (File file : new File(BibtexViewer.HTML_DIR).listFiles()) - file.delete(); - } + public void cleanOutputFolder() { + File[] files = new File(BibtexViewer.OUTPUT_DIR).listFiles(); + if (files != null) + for (File file : files) + file.delete(); + } - protected long countEntries(BibtexFilter filter) { - long number = 0; - for (BibtexEntry entry : entries.values()) - if (filter.include(entry)) - number++; - return number; - } + protected long countEntries(BibtexFilter filter) { + long number = 0; + for (BibtexEntry entry : entries.values()) + if (filter.include(entry)) + number++; + return number; + } - protected String readFromFile(String path, File filename) { - try { - InputStream in = new FileInputStream(path + filename); - StringBuilder out = new StringBuilder(); - byte[] b = new byte[4096]; - for (int n; (n = in.read(b)) != -1;) { - out.append(new String(b, 0, n)); - } - in.close(); - return out.toString(); - } catch (FileNotFoundException e) { - System.out.println("Not Found " + filename); - } catch (IOException e) { - System.out.println("IOException for " + filename); - } - return ""; - } + protected String readFromFile(String path, File filename) { + try { + InputStream in = new FileInputStream(path + filename); + StringBuilder out = new StringBuilder(); + byte[] b = new byte[4096]; + for (int n; (n = in.read(b)) != -1; ) { + out.append(new String(b, 0, n)); + } + in.close(); + return out.toString(); + } catch (FileNotFoundException e) { + System.out.println("Not Found " + filename); + } catch (IOException e) { + System.out.println("IOException for " + filename); + } + return ""; + } - protected void writeToFile(String path, String filename, String content) { - try { - File file = new File(path + filename); - String oldContent = readFromFile(path, new File(filename)); - if (!content.equals(oldContent)) { - System.out.println("Updating " + filename); - BufferedWriter out = new BufferedWriter(new FileWriter(file)); - out.write(content.toString()); - out.close(); - // } else { - // System.out.println("Old content is the same! No update required!"); - } - } catch (FileNotFoundException e) { - System.out.println("Not Found " + filename); - } catch (IOException e) { - System.out.println("IOException for " + filename); - } - } + protected void writeToFile(String path, String filename, String content) { + try { + File file = new File(path + filename); + file.getParentFile().mkdirs(); + String oldContent = readFromFile(path, new File(filename)); + if (!content.equals(oldContent)) { + System.out.println("Updating " + filename); + BufferedWriter out = new BufferedWriter(new FileWriter(file)); + out.write(content); + out.close(); + // } else { + // System.out.println("Old content is the same! No update required!"); + } + } catch (FileNotFoundException e) { + System.out.println("Not Found " + filename); + } catch (IOException e) { + System.out.println("IOException for " + filename); + } + } - public abstract void writeDocument(); + public abstract void writeDocument(); } diff --git a/MibTeX/src/de/mibtex/export/ExportCSV.java b/MibTeX/src/de/mibtex/export/ExportCSV.java index 21d91a2..4185e2e 100644 --- a/MibTeX/src/de/mibtex/export/ExportCSV.java +++ b/MibTeX/src/de/mibtex/export/ExportCSV.java @@ -30,7 +30,7 @@ public void writeDocument() { .append("\"" + entry.venue + "\";").append(entry.year + ";").append(entry.getCitations() + ";") .append("\"" + entry.tags + "\"" + System.getProperty("line.separator")); } - writeToFile(BibtexViewer.HTML_DIR,"literature.csv",CSV.toString()); + writeToFile(BibtexViewer.OUTPUT_DIR,"literature.csv",CSV.toString()); } } diff --git a/MibTeX/src/de/mibtex/export/ExportClassification.java b/MibTeX/src/de/mibtex/export/ExportClassification.java new file mode 100644 index 0000000..2f09530 --- /dev/null +++ b/MibTeX/src/de/mibtex/export/ExportClassification.java @@ -0,0 +1,133 @@ +/* MibTeX - Minimalistic tool to manage your references with BibTeX + * + * Distributed under BSD 3-Clause License, available at Github + * + * https://github.com/tthuem/MibTeX + */ +package de.mibtex.export; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import de.mibtex.BibtexEntry; +import de.mibtex.BibtexViewer; + +/** + * A class that generates a .csv file containing entries classified with respect + * to Thuem's classification. + * + * @author Thomas Thuem + */ +public class ExportClassification extends Export { + + public ExportClassification(String path, String file) throws Exception { + super(path, file); + } + + public final static String SEP = ","; + + public final static String ESC = "\""; + + @Override + public void writeDocument() { + File file = new File(BibtexViewer.CITATION_DIR, "classification.csv"); + System.out.print("Updating " + file.getName() + "... "); + try { + BufferedWriter out = new BufferedWriter(new FileWriter(file)); + out.append("Key" + SEP + "Editor" + SEP); + out.append("Authors" + SEP + "Venue" + + SEP + "Year" + SEP + "Title" + SEP + "Analysis Method" + + SEP + "Analysis Strategy" + SEP + + "Implementation Strategy" + SEP + + "Specification Strategy" + SEP + "SE Layer" + SEP); + out.append("Further Keywords" + SEP + SEP); + out.append(System.lineSeparator()); + for (BibtexEntry entry : entries.values()) { + if (!entry.tagList.isEmpty() + && !entry.tagList.get(0).equalsIgnoreCase("(none)")) + out.append(toClassification(entry)); + } + out.close(); + } catch (FileNotFoundException e) { + System.out.println("Not found " + file.getAbsolutePath()); + } catch (IOException e) { + System.out.println("IOException for " + file.getAbsolutePath()); + } + System.out.println("done."); + } + + private String toClassification(BibtexEntry entry) { + StringBuilder b = new StringBuilder(); + b.append(entry.key + SEP + SEP); + b.append(ESC + entry.author + ESC + SEP); + b.append(entry.venue + SEP); + b.append(entry.year + SEP); + b.append(ESC + entry.title + ESC + SEP); + List tags = new ArrayList(); + for (String tag : entry.tagList) + if (!tag.startsWith("classified by") + && !tag.startsWith("subsumed by")) + tags.add(tag); + for (int i = 0; i < 5; i++) + b.append(ESC + getTags(tags, i) + ESC + SEP); + b.append(ESC); + if (!tags.isEmpty()) + b.append(tags.remove(0)); + for (String tag : tags) + b.append(", " + tag); + b.append(ESC + SEP + SEP); + b.append(System.lineSeparator()); + return b.toString(); + } + + public final static String[][] TAGS = { + { "data-flow analysis", "family-specific analysis", + "fault-tree analysis", "feature-model analysis", + "variant-preserving migration", "model checking", "runtime analysis", + "static analysis", "syntax checking", "product synthesis", + "testing", "test-case generation", "theorem proving", "type checking", "symbolic analysis", "SMT solving", "SAT solving", "BDD solving", + "analysis method undefined" }, + { "family-based analysis", "family-product-based analysis", + "feature-based analysis", "feature-family-based analysis", + "feature-product-based analysis", + "product-family-based analysis", + "regression-based analysis", "sample-based analysis", + "unoptimized product-based analysis", + "analysis strategy undefined", + "optimized product-based analysis", + "product-based analysis" }, + { "clone-and-own", "build system", "preprocessor", + "runtime variability", "components", "services", + "plug-ins", "feature modules", "aspects", "delta modules", + "implementation independent", "implementation undefined", + "product-based implementation", + "family-based implementation", + "feature-based implementation", + "feature-product-based implementation", + "composition-based implementation", + "annotation-based implementation" }, + { "domain-independent specification", "family-wide specification", + "product-based specification", + "feature-based specification", + "feature-product-based specification", + "family-based specification", "specification independent", + "specification undefined" }, + { "requirements", "design", "source code", "program", "theory", + "source code / program" } }; + + private String getTags(List tags, int i) { + String result = ""; + for (String keyword : TAGS[i]) + if (tags.contains(keyword)) { + result += ", " + keyword; + tags.remove(keyword); + } + return result.length() <= 2 ? "" : result.substring(2); + } + +} diff --git a/MibTeX/src/de/mibtex/export/ExportHTML.java b/MibTeX/src/de/mibtex/export/ExportHTML.java index 567d0a6..2230d29 100644 --- a/MibTeX/src/de/mibtex/export/ExportHTML.java +++ b/MibTeX/src/de/mibtex/export/ExportHTML.java @@ -138,7 +138,7 @@ void writeList(String title, List list) { content.append(".htm\">" + o + "
\r\n"); } writeFooter(content); - writeToFile(BibtexViewer.HTML_DIR, filename, content.toString()); + writeToFile(BibtexViewer.OUTPUT_DIR, filename, content.toString()); } void writeToHTML(String filename, BibtexFilter filter) { @@ -146,7 +146,7 @@ void writeToHTML(String filename, BibtexFilter filter) { writeHeader(content, "Literature"); writeBibtex(content, filter); writeFooter(content); - writeToFile(BibtexViewer.HTML_DIR, filename, content.toString()); + writeToFile(BibtexViewer.OUTPUT_DIR, filename, content.toString()); } private void writeHeader(StringBuilder builder, String title) { diff --git a/MibTeX/src/de/mibtex/export/ExportJSON.java b/MibTeX/src/de/mibtex/export/ExportJSON.java index 86cdf7e..b344bfa 100644 --- a/MibTeX/src/de/mibtex/export/ExportJSON.java +++ b/MibTeX/src/de/mibtex/export/ExportJSON.java @@ -39,7 +39,7 @@ public void writeDocument() { .append("},"+System.getProperty("line.separator")); } JSON.append("]"); - writeToFile(BibtexViewer.HTML_DIR,"literature.json",JSON.toString()); + writeToFile(BibtexViewer.OUTPUT_DIR,"literature.json",JSON.toString()); } private String getJSONAttribute(String key, int str) { diff --git a/MibTeX/src/de/mibtex/export/ExportNewHTML.java b/MibTeX/src/de/mibtex/export/ExportNewHTML.java index 2980f69..fa044e8 100644 --- a/MibTeX/src/de/mibtex/export/ExportNewHTML.java +++ b/MibTeX/src/de/mibtex/export/ExportNewHTML.java @@ -1,71 +1,119 @@ -/* MibTeX - Minimalistic tool to manage your references with BibTeX - * - * Distributed under BSD 3-Clause License, available at Github - * - * https://github.com/tthuem/MibTeX - */ -package de.mibtex.export; - -import java.io.File; -import java.util.List; - -import de.mibtex.BibtexEntry; -import de.mibtex.BibtexViewer; - - -/** - * A class that generates a .json file with all BibTeX entries - * - * @author Christopher Sontag - */ -public class ExportNewHTML extends Export{ - - public ExportNewHTML(String path, String file) throws Exception { - super(path, file); - } - - @Override - public void writeDocument() { - StringBuilder JSON = new StringBuilder(); - JSON.append("["); - for (BibtexEntry entry : entries.values()) { - JSON.append("{") - .append(getJSONAttribute("key",entry.key)+",") - .append(getJSONAttribute("authors",entry.authorList)+",") - .append(getJSONAttribute("title", entry.title)+",") - .append(getJSONAttribute("venues", entry.venue)+",") - .append(getJSONAttribute("year", entry.year)+",") - .append(getJSONAttribute("citations", entry.getCitations())+",") - .append(getJSONAttribute("tags", entry.tagList)+",") - .append(getJSONAttribute("pdf", entry.getRelativePDFPath())) - .append("},"); - } - JSON.append("]"); - String input = readFromFile("resources/",new File("index_in.html")); - input = input.replace("JSON_DATA_INSERT_HERE", JSON.toString()); - writeToFile(BibtexViewer.HTML_DIR,"index.html",input); - } - - private String getJSONAttribute(String key, int str) { - return "\""+key+"\":[{\"name\":\""+str+"\"}]"; - } - - private String getJSONAttribute(String key, String str) { - if (!key.equals("pdf")){ - str = BibtexEntry.toURL(str); - } - return "\""+key+"\":[{\"name\":\""+str+"\"}]"; - } - - private String getJSONAttribute(String key, List list) { - String str = "["; - for (int i = 0; i < list.size(); i++) { - str += "{\"name\":\""+BibtexEntry.toURL(list.get(i))+"\"}"; - if (i < (list.size()-1)) { - str += ","; - } - } - str += "]"; - return "\""+key+"\":"+str; - } -} +/* MibTeX - Minimalistic tool to manage your references with BibTeX + * + * Distributed under BSD 3-Clause License, available at Github + * + * https://github.com/tthuem/MibTeX + */ +package de.mibtex.export; + +import java.io.File; +import java.util.HashSet; +import java.util.Set; + +import de.mibtex.BibtexEntry; +import de.mibtex.BibtexViewer; + +/** + * A class that generates a single .html file with all BibTeX entries + * + * @author Christopher Sontag + */ +public class ExportNewHTML extends Export { + + public ExportNewHTML(String path, String file) throws Exception { + super(path, file); + } + + @Override + public void writeDocument() { + String input = readFromFile("resources/", new File("index_in.html")); + StringBuilder HTML = new StringBuilder(); + Set venues = new HashSet<>(); + Set tags = new HashSet<>(); + Set years = new HashSet<>(); + for (BibtexEntry entry : entries.values()) { + HTML.append("") + .append("").append(generateAuthorLinks(entry)).append("") + .append("").append(generateTitleLink(entry)).append("") + .append("").append(generateVenueLink(entry)).append("") + .append("").append(generateTagLinks(entry)).append("") + .append("").append(generateCitationLink(entry)).append("") + .append("").append(generateYearLink(entry)).append("") + .append(""); + venues.add(entry.venue); + years.add(entry.year); + tags.addAll(entry.tagList); + } + input = input.replace("DATA_INSERT_HERE", HTML.toString()); + input = input.replace("INSERT_BIB_PATH", BibtexViewer.BIBTEX_DIR + + "literature.bib"); + input = insertOptionsStr(input, "INSERT_VENUE_OPTIONS", venues); + input = insertOptionsStr(input, "INSERT_TAG_OPTIONS", tags); + input = insertOptionsInt(input, "INSERT_YEAR_OPTIONS", years); + + writeToFile(BibtexViewer.OUTPUT_DIR, "index.html", input); + } + + private String insertOptionsStr(String input, String replace, + Set set) { + StringBuilder HTML = new StringBuilder(); + for (String el : set) { + HTML.append("