/** * Implements grammer rule "Authors" * * @param be * @throws IOException */ private void parseAuthors(BibtexEntry be) throws IOException { // read authors and institutions String authors = ""; String institutions = ""; while (this.lastLine != null && !this.lastLine.equals("") && !startsWithKeyword(recognizedFields)) { // read single author String author = null; String institution = null; boolean institutionDone = false; if (this.lastLine.indexOf('(') >= 0) { author = this.lastLine.substring(0, this.lastLine.indexOf('(')).trim(); institutionDone = this.lastLine.indexOf(')') > 0; institution = this.lastLine.substring(this.lastLine.indexOf('(') + 1, institutionDone && this.lastLine.indexOf(')') > this.lastLine.indexOf('(') + 1 ? this.lastLine.indexOf(')') : this.lastLine.length()).trim(); } else { author = this.lastLine.substring(0, this.lastLine.length()).trim(); institutionDone = true; } readLine(); while (!institutionDone && this.lastLine!= null) { institutionDone = this.lastLine.indexOf(')') > 0; institution += this.lastLine.substring(0, institutionDone ? this.lastLine.indexOf(')') : this.lastLine.length()).trim(); readLine(); } if (author != null) { authors += !authors.equals("") ? " and " + author : "" + author; } if (institution != null) { institutions += !institutions.equals("") ? " and " + institution : "" + institution; } } if (!authors.equals("")) { be.setField("author", authors); } if (!institutions.equals("")) { be.setField("institution", institutions); } }
/** * Parse the entries in the source, and return a List of BibtexEntry * objects. */ public List<BibtexEntry> importEntries(InputStream stream, OutputPrinter status) throws IOException { ArrayList<BibtexEntry> bibitems = new ArrayList<BibtexEntry>(); StringBuffer sb = new StringBuffer(); BufferedReader in = new BufferedReader(ImportFormatReader.getReaderDefaultEncoding(stream)); String str; while ((str = in.readLine()) != null) { if (str.length() < 3) continue; // begining of a new item if (str.substring(0, 6).equals("PMID- ")) sb.append("::").append(str); else { String beg = str.substring(0, 6); if (beg.indexOf(" ") > 0) { sb.append(" ## "); // mark the begining of each field sb.append(str); } else { sb.append("EOLEOL"); // mark the end of each line sb.append(str.trim()); } } } String[] entries = sb.toString().split("::"); // skip the first entry as it is either empty or has document header HashMap<String, String> hm = new HashMap<String, String>(); for (int i = 0; i < entries.length; i++) { String[] fields = entries[i].split(" ## "); if (fields.length == 0) fields = entries[i].split("\n"); String Type = ""; String pages = ""; String shortauthor = ""; String fullauthor = ""; hm.clear(); for (int j = 0; j < fields.length; j++) { System.out.println(">>>"+fields[j]+"<<<"); //empty field don't do anything if (fields[j].length() <= 2) continue; String beg = fields[j].substring(0, 6); String value = fields[j].substring(6); value = value.trim(); if (beg.equals("PT - ")) { // PT = value.replaceAll("JOURNAL ARTICLE", "article").replaceAll("Journal Article", "article"); Type = "article"; //make all of them PT? } else if (beg.equals("TY - ")) { if ("CONF".equals(value)) Type = "inproceedings"; } else if (beg.equals("JO - ")) hm.put("booktitle", value); else if (beg.equals("FAU - ")) { String tmpauthor = value.replaceAll("EOLEOL", " and "); // if there is already someone there then append with "and" if (!"".equals(fullauthor)) fullauthor = fullauthor + " and " + tmpauthor; else fullauthor = tmpauthor; } else if (beg.equals("AU - ")) { String tmpauthor = value.replaceAll("EOLEOL", " and ").replaceAll(" ", ", "); // if there is already someone there then append with "and" if (!"".equals(shortauthor)) shortauthor = shortauthor + " and " + tmpauthor; else shortauthor = tmpauthor; } else if (beg.equals("TI - ")) hm.put("title", value.replaceAll("EOLEOL", " ")); else if (beg.equals("TA - ")) hm.put("journal", value.replaceAll("EOLEOL", " ")); else if (beg.equals("AB - ")) hm.put("abstract", value.replaceAll("EOLEOL", " ")); else if (beg.equals("PG - ")) pages = value.replaceAll("-", "--"); else if (beg.equals("IP - ")) hm.put("number", value); else if (beg.equals("DP - ")) { String[] parts = value.split(" "); // sometimes this is just year, sometimes full date hm.put("year", parts[0]); } else if (beg.equals("VI - ")) hm.put("volume", value); else if (beg.equals("AID - ")) { String[] parts = value.split(" "); if ("[doi]".equals(parts[1])) { hm.put("doi", parts[0]); hm.put("url", "http://dx.doi.org/" + parts[0]); } } } if (!"".equals(pages)) hm.put("pages", pages); if (!"".equals(fullauthor)) hm.put("author", fullauthor); else if (!"".equals(shortauthor)) hm.put("author", shortauthor); BibtexEntry b = new BibtexEntry(BibtexFields.DEFAULT_BIBTEXENTRY_ID, Globals.getEntryType(Type)); // id assumes an existing database so don't // create one here b.setField(hm); // the first bibitem is always empty, presumably as a result of trying // to parse header informaion. So add only if we have at least author or // title fields. if (hm.get("author") != null || hm.get("title") != null) bibitems.add(b); } return bibitems; }
Clone fragments detected by clone detection tool
File path: /jabref-2.10/src/java/net/sf/jabref/imports/RepecNepImporter.java File path: /jabref-2.10/src/java/net/sf/jabref/imports/BiomailImporter.java
Method name: void parseAuthors(BibtexEntry) Method name: List importEntries(InputStream, OutputPrinter)
Number of AST nodes: 1 Number of AST nodes: 3
1
/**
1
/**
2
   * Implements grammer rule "Authors"
2
     * Parse the entries in the source, and return a List of BibtexEntry
3
   * 
3
     * objects.
4
   * @param be
4
     */
5
   * @throws IOException
5
    public List<BibtexEntry> importEntries(InputStream stream, OutputPrinter status) throws IOException {
6
   */
6
        ArrayList<BibtexEntry> bibitems = new ArrayList<BibtexEntry>();
7
  private void parseAuthors(BibtexEntry be) throws IOException {
7
        StringBuffer sb = new StringBuffer();
8
    // read authors and institutions
8
9
    String authors = "";
9
        BufferedReader in =
10
    String institutions = "";
10
                new BufferedReader(ImportFormatReader.getReaderDefaultEncoding(stream));
11
    while (this.lastLine != null && !this.lastLine.equals("") && !startsWithKeyword(recognizedFields)) {
11
12
      
12
        String str;
13
      // read single author
13
14
      String author = null;
14
        while ((str = in.readLine()) != null) {
15
      String institution = null;
15
            if (str.length() < 3)
16
      boolean institutionDone = false;
16
                continue;
17
      if (this.lastLine.indexOf('(') >= 0) {
17
18
        author = this.lastLine.substring(0, this.lastLine.indexOf('(')).trim();
18
            // begining of a new item
19
        institutionDone = this.lastLine.indexOf(')') > 0;
19
            if (str.substring(0, 6).equals("PMID- "))
20
        institution = this.lastLine.substring(this.lastLine.indexOf('(') + 1, institutionDone && this.lastLine.indexOf(')') > this.lastLine.indexOf('(') + 1 ? this.lastLine.indexOf(')') : this.lastLine.length()).trim();
20
                sb.append("::").append(str);
21
      } else {
21
            else {
22
        author = this.lastLine.substring(0, this.lastLine.length()).trim();
22
                String beg = str.substring(0, 6);
23
        institutionDone = true;
23
24
      }
24
                if (beg.indexOf(" ") > 0) {
25
      
25
                    sb.append(" ## "); // mark the begining of each field
26
      readLine();
26
                    sb.append(str);
27
      while (!institutionDone && this.lastLine!= null) {
27
                } else {
28
        institutionDone = this.lastLine.indexOf(')') > 0;
28
                    sb.append("EOLEOL"); // mark the end of each line
29
        institution += this.lastLine.substring(0, institutionDone ? this.lastLine.indexOf(')') : this.lastLine.length()).trim();
29
                    sb.append(str.trim());
30
        readLine();
30
                }
31
      }
31
            }
32
      
32
        }
33
      if (author != null) {
33
34
        authors += !authors.equals("") ? " and " + author : "" + author;
34
        String[] entries = sb.toString().split("::");
35
      }
35
36
      if (institution != null) {
36
        // skip the first entry as it is either empty or has document header
37
        institutions += !institutions.equals("") ? " and " + institution : "" + institution;
37
        HashMap<String, String> hm = new HashMap<String, String>();
38
      }            
38
39
    }
39
        for (int i = 0; i < entries.length; i++) {
40
    
40
            String[] fields = entries[i].split(" ## ");
41
    if (!authors.equals("")) {
41
42
      be.setField("author", authors);
42
            if (fields.length == 0)
43
    }
43
                fields = entries[i].split("\n");
44
    if (!institutions.equals("")) {
44
45
      be.setField("institution", institutions);
45
            String Type = "";
46
    }
46
            String pages = "";
47
  }
47
            String shortauthor = "";
48
            String fullauthor = "";
49
            hm.clear();
50
51
            for (int j = 0; j < fields.length; j++) {
52
                System.out.println(">>>"+fields[j]+"<<<");
53
54
                //empty field don't do anything
55
                if (fields[j].length() <= 2)
56
                    continue;
57
58
                String beg = fields[j].substring(0, 6);
59
                String value = fields[j].substring(6);
60
                value = value.trim();
61
62
                if (beg.equals("PT  - ")) {
63
                    // PT = value.replaceAll("JOURNAL ARTICLE", "article").replaceAll("Journal Article", "article");
64
                    Type = "article"; //make all of them PT?
65
                } else if (beg.equals("TY  - ")) {
66
                    if ("CONF".equals(value))
67
                        Type = "inproceedings";
68
                } else if (beg.equals("JO  - "))
69
                    hm.put("booktitle", value);
70
                else if (beg.equals("FAU - ")) {
71
                    String tmpauthor = value.replaceAll("EOLEOL", " and ");
72
73
                    // if there is already someone there then append with "and"
74
                    if (!"".equals(fullauthor))
75
                        fullauthor = fullauthor + " and " + tmpauthor;
76
                    else
77
                        fullauthor = tmpauthor;
78
                } else if (beg.equals("AU  - ")) {
79
                    String tmpauthor = value.replaceAll("EOLEOL", " and ").replaceAll(" ", ", ");
80
81
                    // if there is already someone there then append with "and"
82
                    if (!"".equals(shortauthor))
83
                        shortauthor = shortauthor + " and " + tmpauthor;
84
                    else
85
                        shortauthor = tmpauthor;
86
                } else if (beg.equals("TI  - "))
87
                    hm.put("title", value.replaceAll("EOLEOL", " "));
88
                else if (beg.equals("TA  - "))
89
                    hm.put("journal", value.replaceAll("EOLEOL", " "));
90
                else if (beg.equals("AB  - "))
91
                    hm.put("abstract", value.replaceAll("EOLEOL", " "));
92
                else if (beg.equals("PG  - "))
93
                    pages = value.replaceAll("-", "--");
94
                else if (beg.equals("IP  - "))
95
                    hm.put("number", value);
96
                else if (beg.equals("DP  - ")) {
97
                    String[] parts = value.split(" "); // sometimes this is just year, sometimes full date
98
                    hm.put("year", parts[0]);
99
                } else if (beg.equals("VI  - "))
100
                    hm.put("volume", value);
101
                else if (beg.equals("AID - ")) {
102
                    String[] parts = value.split(" ");
103
                    if ("[doi]".equals(parts[1])) {
104
                        hm.put("doi", parts[0]);
105
                        hm.put("url", "http://dx.doi.org/" + parts[0]);
106
                    }
107
                }
108
            }
109
110
            if (!"".equals(pages))
111
                hm.put("pages", pages);
112
            if (!"".equals(fullauthor))
113
                hm.put("author", fullauthor);
114
            else if (!"".equals(shortauthor))
115
                hm.put("author", shortauthor);
116
117
            BibtexEntry b =
118
                    new BibtexEntry(BibtexFields.DEFAULT_BIBTEXENTRY_ID, Globals.getEntryType(Type)); // id assumes an existing database so don't
119
120
            // create one here
121
            b.setField(hm);
122
123
            // the first bibitem is always empty, presumably as a result of trying
124
            // to parse header informaion. So add only if we have at least author or
125
            // title fields.
126
            if (hm.get("author") != null || hm.get("title") != null)
127
                bibitems.add(b);
128
        }
129
130
        return bibitems;
131
    }
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements3
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)0.0
    Similarity Score1.000
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    21
    institutions += !institutions.equals("") ? " and " + institution : "" + institution;
    21
    institutions += !institutions.equals("") ? " and " + institution : "" + institution;
    43
    if (!"".equals(fullauthor))
    Differences
    Expression1Expression2Difference
    ""fullauthorTYPE_COMPATIBLE_REPLACEMENT
    institutions""TYPE_COMPATIBLE_REPLACEMENT
    institutionsfullauthorVARIABLE_NAME_MISMATCH
    institutionsfullauthorVARIABLE_NAME_MISMATCH
    " and "fullauthorTYPE_COMPATIBLE_REPLACEMENT
    institution" and "TYPE_COMPATIBLE_REPLACEMENT
    " and " + institutionfullauthor + " and " + tmpauthorINFIX_EXTENDED_OPERAND_NUMBER_MISMATCH
    "" + institutiontmpauthorTYPE_COMPATIBLE_REPLACEMENT
    43
    if (!"".equals(fullauthor))
                                                                                                    
    44
    fullauthor = fullauthor + " and " + tmpauthor;
    Differences
    Expression1Expression2Difference
    institutionsfullauthorVARIABLE_NAME_MISMATCH
    " and "fullauthorTYPE_COMPATIBLE_REPLACEMENT
    institution" and "TYPE_COMPATIBLE_REPLACEMENT
    " and " + institutionfullauthor + " and " + tmpauthorINFIX_EXTENDED_OPERAND_NUMBER_MISMATCH
    44
    fullauthor = fullauthor + " and " + tmpauthor;
            
    else
                                                      
    45
    fullauthor = tmpauthor;
    Differences
    Expression1Expression2Difference
    institutionsfullauthorVARIABLE_NAME_MISMATCH
    "" + institutiontmpauthorTYPE_COMPATIBLE_REPLACEMENT
    45
    fullauthor = tmpauthor;
    Precondition Violations (0)
    Row Violation