Skip to content

Commit 4b60f49

Browse files
committed
Duplicate lines to linesRis folder
1 parent c9ccad4 commit 4b60f49

24 files changed

+846
-1
lines changed

linesRis/TestFromIndicesGetChar.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
def importForGetChar():
2+
# import module:
3+
4+
import firstname
5+
6+
# locally name function(s):
7+
8+
allnames = firstname.allnames()
9+
10+
# firstinitial = firstinitial(allnames)
11+
12+
# define function:
13+
return allnames
14+
15+
allnames = importForGetChar()
16+
17+
def getCharFromIndices(allnames):
18+
19+
20+
import firstnameinitialscaller
21+
22+
firstNameInitialsCaller = firstnameinitialscaller.firstNameInitialsCaller()
23+
24+
fNIC = firstNameInitialsCaller
25+
26+
27+
characterList = []
28+
29+
30+
for index in fNIC:
31+
# print(index)
32+
aCharacter = allnames[index]
33+
characterList.append(aCharacter)
34+
35+
36+
37+
return characterList
38+
39+
# getCharFromIndices = getCharFromIndices(allnames)
40+
# print(getCharFromIndices)

linesRis/__init__.py

Whitespace-only changes.

linesRis/author.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
def author():
2+
"""
3+
encapsulate author program in a
4+
function
5+
"""
6+
# imports
7+
8+
import nltk
9+
import re
10+
11+
# file
12+
13+
f_name="BibTex.bib"
14+
15+
def opener(f_name):
16+
file = open(f_name, 'r', encoding="utf8")
17+
return file
18+
19+
file=opener(f_name)
20+
21+
# end prep
22+
23+
endline=''
24+
file = opener(f_name)
25+
for line in file:
26+
if (re.search('^author',line)):
27+
starter=line
28+
line=line.lstrip('author = {')
29+
line=line.rstrip('},\n')
30+
31+
endline=line
32+
# print(endline)
33+
return endline
34+
# author=author()
35+
# print(author)

linesRis/checkSpacesAuthorList.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# import firstname # has allnames
2+
# allnames=firstname.allnames()
3+
# import firstname2 # has spacesInAuthorString
4+
def checkIfFirstNameBetweenSpaces(firstname, firstname2, allnames):
5+
spacesList=firstname2.spacesInAuthorString(allnames)
6+
# import useSpacesInAuthorString
7+
# spacesList
8+
9+
for spaceIndex, space in enumerate(spacesList):
10+
new=''
11+
if(spaceIndex!=0):
12+
spaceLastIndex = spaceIndex-1
13+
spaceNextIndex = spaceIndex
14+
import firstname2
15+
firstInitialIndices=firstname2.firstinitial(allnames)
16+
for letterIndex in firstInitialIndices:
17+
if letterIndex <spaceNextIndex and letterIndex > spaceLastIndex:
18+
startLetterIndex=letterIndex
19+
endLetterIndex=spaceNextIndex-1
20+
endLetterIndexRule=endLetterIndex+1
21+
if letterIndex != startLetterIndex:
22+
# for firstNameLetter in allnames.slice[startLetter,endLetterIndexRule]:
23+
# firstNameLetter.replace('_'):
24+
import TestFromIndicesGetChar
25+
characterList = TestFromIndicesGetChar.getCharFromIndices(allnames)
26+
import firstnameinitialscaller
27+
firstInitialIndices = firstnameinitialscaller.firstNameInitialsCaller()
28+
for characterIndex, character in zip(firstInitialIndices,characterList):
29+
allnames.strip(startLetterIndex,endLetterIndexRule).replace(allnames.strip(startLetterIndex,endLetterIndexRule),allnames[startLetterIndex])
30+
allnames=allnames.strip(0,startLetterIndex)+allnames.strip(startLetterIndex,(startLetterIndex+1))+allnames.strip((startLetterIndex+1),-1)
31+
new = allnames.strip(startLetterIndex,endLetterIndexRule)
32+
# return spacesList
33+
return allnames
34+
35+
# print(checkIfFirstNameBetweenSpaces())
36+
37+
def getNameNumbers():
38+
import firstname # has allnames
39+
# import firstname # has allnames
40+
allnames=firstname.allnames()
41+
import firstname2 # has spacesInAuthorString
42+
spacesList=firstname2.spacesInAuthorString(allnames)
43+
indivNames=allnames.split(' ')
44+
return indivNames
45+
46+
# indivNames=getNameNumbers()
47+
# print(indivNames)

linesRis/doi.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
def doi():
2+
"""
3+
encapsulate author program in a
4+
function
5+
"""
6+
# imports
7+
8+
import nltk
9+
import re
10+
11+
# file
12+
13+
f_name="BibTex.bib"
14+
15+
def opener(f_name):
16+
file = open(f_name, 'r', encoding="utf8")
17+
return file
18+
19+
file=opener(f_name)
20+
21+
# end prep
22+
23+
endline=''
24+
file = opener(f_name)
25+
for line in file:
26+
if (re.search('^doi',line)):
27+
starter=line
28+
line=line.lstrip('doi = {')
29+
line=line.rstrip('},\n')
30+
31+
endline=line
32+
# print(endline)
33+
return endline
34+
# author=author()
35+
# print(author)

linesRis/firstname.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
def allnames():
2+
import names3
3+
4+
names3=names3.names3()
5+
return names3
6+
# allnames=allnames() #
7+
# print('allnames:', allnames)
8+
9+
def firstinitial(allnames):
10+
# import firstname
11+
# firstname=firstname.firstname()
12+
# firstname=firstname()
13+
firstInitialIndices=[]
14+
# print('line 13: allnames:', allnames)#
15+
# print(allnames[7]==',')#
16+
for letterIndex, letter in enumerate(allnames):
17+
# print('letter', letterIndex, 'is:', letter)
18+
commaIndex=(letterIndex-2)
19+
spaceIndex=(letterIndex-1)
20+
# print('test:')
21+
# print(allnames[commaIndex])
22+
if (allnames[commaIndex]==','):
23+
# if ((letterIndex-2)=='/,'):
24+
# print('comma 2 ago')
25+
if (allnames[spaceIndex]==' '):
26+
# print('space one ago')
27+
# print('letterIndex',letterIndex)
28+
firstInitialIndices
29+
# firstinitial=allnames[0]
30+
return firstInitialIndices
31+
32+
# firstinitial=firstinitial(allnames)#
33+
# print('firstinitial',firstinitial)#
34+
35+
def checkForComma(allnames):
36+
import nltk
37+
tokens = nltk.word_tokenize(allnames)
38+
commaIndexes=[]
39+
for i, char in enumerate(allnames):
40+
if char == ',':
41+
print(',')
42+
commaIndexes.append(i)
43+
return commaIndexes
44+
45+
# checkForComma = checkForComma(allnames)#
46+
# print(checkForComma)#
47+
48+
def printFromCommaIndex(allnames, checkForComma):
49+
"""
50+
input arguments:
51+
52+
- aString:
53+
allnames
54+
55+
- checkForComma:
56+
(variable (type:list))
57+
takes a list of commas
58+
returned from checkForComma
59+
and called and saved to
60+
variable checkForComma
61+
62+
output:
63+
returns
64+
charAtEachCommaIndex
65+
"""
66+
67+
68+
69+
return charAtEachCommaIndex

linesRis/firstname2.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
def firstinitial(allnames):
2+
3+
firstInitialIndices=[]
4+
5+
for letterIndex, letter in enumerate(allnames):
6+
7+
commaIndex=(letterIndex-2)
8+
spaceIndex=(letterIndex-1)
9+
10+
if (allnames[commaIndex]==','): # print('comma 2 ago')
11+
if (allnames[spaceIndex]==' '): # print('space one ago')
12+
# print('letterIndex',letterIndex)
13+
firstInitialIndices.append(letterIndex)
14+
# print(firstInitialIndices)
15+
# firstinitial=allnames[0]
16+
return firstInitialIndices
17+
18+
def spacesInAuthorString(allnames):
19+
20+
spacesList = []
21+
22+
for letterIndex, letter in enumerate(allnames):
23+
24+
if letter==' ':
25+
spacesList.append(letterIndex)
26+
27+
return spacesList
28+
29+
# import firstname
30+
# allnames=firstname.allnames()
31+
# spacesInAuthorString=spacesInAuthorString(allnames)
32+
# print(spacesInAuthorString)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def firstNameInitialsCaller():
2+
import firstname
3+
4+
allnames= firstname.allnames()
5+
# print(allnames)
6+
7+
# firstinitial = firstinitial(allnames)
8+
# print(firstinitial)
9+
10+
11+
12+
import firstname2
13+
14+
firstInitialIndices = firstname2.firstinitial(allnames)
15+
16+
# print(firstInitialIndices)
17+
return firstInitialIndices
18+
19+
# firstNameInitialsCaller = firstNameInitialsCaller()
20+
# print(firstNameInitialsCaller)

linesRis/journal.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
def journal():
2+
"""
3+
reads BibTex.bib file
4+
outputs
5+
journal name
6+
"""
7+
8+
9+
10+
# imports
11+
12+
import nltk
13+
import re
14+
15+
# file
16+
17+
f_name="BibTex.bib"
18+
19+
def opener(f_name):
20+
file = open(f_name, 'r', encoding="utf8")
21+
return file
22+
23+
file=opener(f_name)
24+
25+
# end prep
26+
27+
endline=''
28+
file = opener(f_name)
29+
for line in file:
30+
if (re.search('^journal',line)):
31+
starter=line
32+
line=line.lstrip('journal = {')
33+
line=line.rstrip('},\n')
34+
line=line.rstrip(' ')
35+
line=line.rstrip('},')
36+
endline=line
37+
# print(endline)
38+
# print(len(endline))
39+
return endline

linesRis/names.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import nltk
2+
import re
3+
4+
f_name="Bibtex.bib"
5+
file = open("Bibtex.bib", 'r', encoding="utf8")
6+
holder=""
7+
import author
8+
9+
author=author.author()
10+
11+
for line in file:
12+
if (re.search('^, ',line)):
13+
tokens = nltk.word_tokenize(line)
14+
tagged_list = nltk.pos_tag(tokens)
15+
16+
for k4, v4 in enumerate(tagged_list):
17+
for tagged_keys_for_use, _ in tagged_list: # splits out v4
18+
19+
# tagged_keys_for_use
20+
21+
# tagged_list = tagged
22+
23+
# highlights x and x1 related:
24+
x = tagged_list[k4][0] # x tuple
25+
x1 = tagged_keys_for_use # x1 string
26+
remove_end = tagged_list[0:-2] # cut space and last curly bracket
27+
for k,tuple_key_word in enumerate(remove_end, start = 0):
28+
tuple_key_word_zero=tuple_key_word[0]
29+
len_remove_end=len(remove_end)
30+
if(tuple_key_word[0]!=len(remove_end)): # remove_end may be line instead
31+
holder+=tuple_key_word[0]+' '
32+
else:
33+
holder+=tuple_key_word[0]
34+
if(re.search('^journal',holder)):
35+
start_after_journal=slice(len_journal,None,1)
36+
no_journal=holder[start_after_journal]
37+
tokens_no_journal = nltk.word_tokenize(no_journal)
38+
tagged_tokens_no_journal = nltk.pos_tag(tokens_no_journal)
39+
no_journal_minus_starting_curly_bracket = tagged_tokens_no_journal[1:] # cut space and last curly bracket
40+
holder2=''
41+
list_of_keys=[]
42+
for k3,v3 in no_journal_minus_starting_curly_bracket:
43+
list_of_keys.append(k3)
44+
#print(list_of_keys)
45+
for k2,v2 in enumerate(list_of_keys):
46+
if (k2!=len(list_of_keys)):
47+
if (k2+1!=len(list_of_keys)): # avoids index out of range error
48+
#print('line 35:',list_of_keys[k2+1])
49+
if(v2 != ',' and list_of_keys[k2+1]==','): # if this isn't but next element is a comma:
50+
#print('\n', 'line 37: start of 1 off block for comma next',sep="")
51+
#print('line 38: (k2) :',k2)
52+
#print('line 39: (v2), list_of_keys[k2+1]:',v2, list_of_keys[k2+1])
53+
#print('line 40: so, list_of_keys[k2+1] = ', list_of_keys[k2+1])
54+
holder2 += v2 # wait, save space for next element coming in.
55+
#print('line 42: holder2',holder2)
56+
#print('line 43: end of 1 off block for comma next', '\n')
57+
elif(v2 != ',' and list_of_keys[k2+1]!=','): # if this element is not a comma, and neither is next:
58+
holder2 += v2 + ' ' # then can add a space
59+
#print('line 46: holder2', holder2)
60+
elif(k2+1 == len(list_of_keys)):
61+
holder2 += v2 # experience
62+
else:
63+
# no space if last element
64+
holder2+=v2[0]
65+
print('line 52: (post last for-if, which assembles holder2) holder2:', holder2 )

0 commit comments

Comments
 (0)