<commit_before>// Looks for citation: <NAME>, Jewish Agricultural Utopias in America, 1880-1910 (Detroit: Wayne State University Press, 1991), 123.
// on https://jwa.org/teach/livingthelegacy/jews-and-farming-in-america
// Parse citation to get creator:"<NAME>" AND title:"Jewish Agricultural Utopias in America"
// search archive to get https://archive.org/details/jewishagricultur0000hers

$(document).ready(function () {
  findCitations()
})

function findCitations () {
  let candidates = $("a[href^='#_ftnref']").parent()
  for (let i = 0; i < candidates.length; i++) {
    let citation = getCitation(candidates[i].innerText)
    if (citation) {
      advancedSearch(citation, candidates[i])
    }
  }
}

function getCitation (cit) {
  str = cit.replace(/^[^a-zA-Z]*/, '')
  if (str.length == 0) {
    return null
  } else {
    let publisher = str.match(/\(.*\d\d\d\d\)/)[0]
    let halves = str.split(publisher)
    let pages = halves[1].split(',').filter($.isNumeric).map(Number)
    let commaLoc = halves[0].indexOf(',')
    let title, author
    if (commaLoc >= 0) {
      author = halves[0].slice(0, commaLoc)
      title = halves[0].slice(commaLoc + 1)
    } else {
      author = null
      title = halves[0]
    }
    return {
      title: title.replace(/^\s/, '').replace(/\s$/, ''),
      author: author,
      pages: pages,
      publisher: publisher.slice(1, -1)

    }
  }
}

function getAdvancedSearchQuery (parsed_cit) {
  ({ author, title } = parsed_cit)
  // format author
  author = formatAuthor(author)
  return 'creator:"' + author + '" AND title:"' + title + '"'
}

function formatAuthor (auth) {<commit_msg>handles advanced search when no author in citation<commit_after>// Looks for citation: <NAME>, Jewish Agricultural Utopias in America, 1880-1910 (Detroit: Wayne State University Press, 1991), 123.
// on https://jwa.org/teach/livingthelegacy/jews-and-farming-in-america
// Parse citation to get creator:"<NAME>" AND title:"Jewish Agricultural Utopias in America"
// search archive to get https://archive.org/details/jewishagricultur0000hers

$(document).ready(function () {
  findCitations()
})

function findCitations () {
  let candidates = $("a[href^='#_ftnref']").parent()
  for (let i = 0; i < candidates.length; i++) {
    let citation = getCitation(candidates[i].innerText)
    if (citation) {
      advancedSearch(citation, candidates[i])
    }
  }
}

function getCitation (cit) {
  str = cit.replace(/^[^a-zA-Z]*/, '')
  if (str.length == 0) {
    return null
  } else {
    let publisher = str.match(/\(.*\d\d\d\d\)/)[0]
    let halves = str.split(publisher)
    let pages = halves[1].split(',').filter($.isNumeric).map(Number)
    let commaLoc = halves[0].indexOf(',')
    let title, author
    if (commaLoc >= 0) {
      author = halves[0].slice(0, commaLoc)
      title = halves[0].slice(commaLoc + 1)
    } else {
      author = null
      title = halves[0]
    }
    return {
      title: title.replace(/^\s/, '').replace(/\s$/, ''),
      author: author,
      pages: pages,
      publisher: publisher.slice(1, -1)

    }
  }
}

function getAdvancedSearchQuery (parsed_cit) {
  ({ author, title } = parsed_cit)
  // format author
  if (author){
    author = formatAuthor(author)
    return 'creator:"' + author + '" AND title:"' + title + '"'
  }else{
    return 'title:"' + title +'"'
  }
}

function formatAuthor (auth) {
{'fraction_non_alphanumeric': 0.16928550252001187, 'fraction_numerical': 0.01897420693744441, 'mean_word_length': 3.18091697645601, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2601334', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1128, 'n_words': 267}