Description Usage Arguments Value Author(s) Examples
View source: R/assign_citation_numbers.R
This function assigns Citationnumbers to the extracted Citations from the rebuild_data_source_cocit function
1 | assign_citation_numbers(cits)
|
cits |
A Dataframe with all Citations with the following dimensions: x, autor, jahr, journal, version, seite, CR, DOI |
The same dataframe as the input but with assigned Citationnumbers. Assigned means, for every unique Citation there is an unique Citationnumber choosen.
MFinst
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (cits)
{
start_time = Sys.time()
cits = type.convert(cits, as.is = TRUE)
cr_number = 0
cr_nummer_eintrag = "CR"
cits_length = length(cits$x)
for (i in 2:cits_length) {
checkCit = FALSE
canCheck = TRUE
citation_infos = cits[i,]
cr = citation_infos$CR
autor = citation_infos$autor
if (!grepl("?", autor)) {
canCheck = FALSE
}
if (cr == "CR") {
canCheck = FALSE
}
if (canCheck) {
jahr = citation_infos$jahr
doi = citation_infos$DOI
if (cr == "0") {
cr_number = cr_number + 1
cr_nummer_eintrag = paste("CR", cr_number, sep = "")
checkCit = TRUE
}
if (checkCit) {
autor_jahr_matches = cits$autor[(cits$autor ==
autor &
cits$jahr == jahr)]
if (length(autor_jahr_matches) > 0) {
if (length(autor_jahr_matches) == 1) {
cits$CR[(cits$autor == autor & cits$jahr ==
jahr)] = cr_nummer_eintrag
}
else {
autor_jahr_doi_matches = cits$autor[(cits$autor ==
autor &
cits$jahr == jahr & cits$DOI ==
doi)]
if (length(autor_jahr_doi_matches) > 0 &&
trimws(doi) != "") {
cits$CR[(cits$autor == autor & cits$jahr ==
jahr &
cits$DOI == doi)] = cr_nummer_eintrag
}
else {
journal = citation_infos$journal
if (!grepl("?", journal, fixed = TRUE) &
!grepl("]", journal, fixed = TRUE) &
!grepl("[", journal, fixed = TRUE)) {
journals_for_autor = cits$journal[(cits$autor ==
autor &
cits$jahr == jahr)]
unique_journals_for_autor = unique(journals_for_autor)
similarJournals = ""
if (length(unique_journals_for_autor) >
1) {
for (j in 1:length(unique_journals_for_autor)) {
single_journal = unique_journals_for_autor[j]
if (is.na(single_journal) || is.na(journal)) {
isSimilar = FALSE
} else {
isSimilar = grepl(single_journal,
journal, fixed = TRUE)
}
if (isSimilar) {
if (similarJournals != "") {
similarJournals = paste(similarJournals,
single_journal,
sep = "|")
}
else {
similarJournals = single_journal
}
}
}
similarJournals <- gsub(
pattern = "\\+",
replacement = "\\\\+",
x = similarJournals
)
similarJournals <- gsub(
pattern = "\\.",
replacement = "\\\\.",
x = similarJournals
)
similarJournals <- gsub(
pattern = "\\-",
replacement = "\\\\-",
x = similarJournals
)
similarJournals <- gsub(
pattern = "\\)",
replacement = "\\\\)",
x = similarJournals
)
similarJournals <- gsub(
pattern = "\\(",
replacement = "\\\\(",
x = similarJournals
)
similarJournals <- gsub(
pattern = "\\*",
replacement = "\\\\*",
x = similarJournals
)
similarJournals <- gsub(
pattern = "\\!",
replacement = "\\\\!",
x = similarJournals
)
cits$CR[(
cits$autor == autor & cits$jahr ==
jahr &
grepl(similarJournals, cits$journal)
)] = cr_nummer_eintrag
}
else {
journal_matches = cits$CR[(
grepl(journal,
cits$journal, fixed = TRUE) &
cits$autor ==
autor &
cits$jahr == jahr
)]
if (length(journal_matches) > 0) {
cits$CR[(
grepl(journal, cits$journal,
fixed = TRUE) & cits$autor ==
autor &
cits$jahr == jahr
)] = cr_nummer_eintrag
}
else {
cits$CR[i] = cr_nummer_eintrag
}
}
}
else {
cits$CR[i] = cr_nummer_eintrag
}
}
}
}
}
}
if ((i %% 20) == 0) {
print(paste(i, "of", cits_length, sep = " "))
}
}
end_time = Sys.time()
final_time = end_time - start_time
print(final_time)
cits = cits[-1,]
colnames(cits)[2] = 'PNo'
colnames(cits)[3] = 'Autor'
colnames(cits)[4] = 'Jahr'
colnames(cits)[8] = 'CRNo'
return(cits)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.