Пример #1
0
  @Test
  public void monthFieldSpecialSyntax() throws IOException {
    // @formatter:off
    String bibtexEntry =
        "@Article{test,"
            + OS.NEWLINE
            + "  Author                   = {Foo Bar},"
            + OS.NEWLINE
            + "  Month                    = mar,"
            + OS.NEWLINE
            + "  Number                   = {1}"
            + OS.NEWLINE
            + "}";
    // @formatter:on

    // read in bibtex string
    ParserResult result = BibtexParser.parse(new StringReader(bibtexEntry));
    Collection<BibEntry> entries = result.getDatabase().getEntries();
    BibEntry entry = entries.iterator().next();

    // modify month field
    Set<String> fields = entry.getFieldNames();
    assertTrue(fields.contains("month"));
    assertEquals("#mar#", entry.getFieldOptional("month").get());

    // write out bibtex string
    StringWriter stringWriter = new StringWriter();
    writer.write(entry, stringWriter, BibDatabaseMode.BIBTEX);
    String actual = stringWriter.toString();

    assertEquals(bibtexEntry, actual);
  }
Пример #2
0
 private boolean isAnyFieldSetForSelectedEntry(List<String> fieldnames) {
   if (panel.getMainTable().getSelectedRowCount() == 1) {
     BibEntry entry = panel.getMainTable().getSelected().get(0);
     return !Collections.disjoint(fieldnames, entry.getFieldNames());
   }
   return false;
 }
Пример #3
0
  public static double compareEntriesStrictly(BibEntry one, BibEntry two) {
    HashSet<String> allFields = new HashSet<>();
    allFields.addAll(one.getFieldNames());
    allFields.addAll(two.getFieldNames());

    int score = 0;
    for (String field : allFields) {
      Object en = one.getField(field);
      Object to = two.getField(field);
      if (((en != null) && (to != null) && en.equals(to)) || ((en == null) && (to == null))) {
        score++;
      }
    }
    if (score == allFields.size()) {
      return 1.01; // Just to make sure we can
      // use score>1 without
      // trouble.
    }
    return (double) score / allFields.size();
  }
Пример #4
0
  @Override
  public List<IntegrityMessage> check(BibEntry entry) {
    List<IntegrityMessage> result = new ArrayList<>();
    for (String field : entry.getFieldNames()) {
      if (InternalBibtexFields.getFieldProperties(field).contains(FieldProperty.PERSON_NAMES)) {
        Optional<String> value = entry.getField(field);
        if (!value.isPresent()) {
          return Collections.emptyList();
        }

        String valueTrimmedAndLowerCase = value.get().trim().toLowerCase();
        if (valueTrimmedAndLowerCase.startsWith("and ")
            || valueTrimmedAndLowerCase.startsWith(",")) {
          result.add(
              new IntegrityMessage(Localization.lang("should start with a name"), entry, field));
        } else if (valueTrimmedAndLowerCase.endsWith(" and")
            || valueTrimmedAndLowerCase.endsWith(",")) {
          result.add(
              new IntegrityMessage(Localization.lang("should end with a name"), entry, field));
        }
      }
    }
    return result;
  }