Skip to content

Commit f7608a3

Browse files
committed
Merged from master version 0.9.5
Former-commit-id: 93d64a8
1 parent 5217caf commit f7608a3

File tree

13 files changed

+891
-519
lines changed

13 files changed

+891
-519
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ metaknowledge is a Python3 library that simplifies bibliometric research using W
44

55
The website can be found at [networkslab.org/metaknowledge](http://networkslab.org/metaknowledge/).
66

7+
## Currently in Beta
8+
metaknowledge is in the final stages of testing before a 1.0 release different versions may behave differently.
9+
710
##Installing
811
To install run `python3 setup.py install`
912

metaknowledge/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from .record import Record, recordParser, BadISIRecord
3030
from .citation import Citation, BadCitation, filterNonJournals
3131
from .recordCollection import RecordCollection, isiParser
32-
from .graphHelpers import write_edgeList, write_nodeAttributeFile, write_graph, read_graph, _ProgressBar, drop_edges, drop_nodesByDegree, drop_nodesByCount, graphStats
32+
from .graphHelpers import write_edgeList, write_nodeAttributeFile, write_graph, read_graph, _ProgressBar, drop_edges, drop_nodesByDegree, drop_nodesByCount, mergeGraphs, graphStats
3333
from .constants import VERBOSE_MODE
3434
#from .blondel import blondel, modularity
3535
from .diffusion import diffusionGraph, diffusionCount

metaknowledge/bin/metaknowledgeDocsGen.py

Lines changed: 124 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import importlib
1111
import re
1212

13-
documentedModules = ['tagProcessing', 'visual', 'journalAbbreviations']
13+
documentedModules = ['visual', 'journalAbbreviations', 'tagProcessing']
1414

1515
docsPrefix = time.strftime("%Y-%m-%d-")
1616

@@ -19,19 +19,38 @@
1919
'tagProcessing' : "All the tags and how they are handled",
2020
'journalAbbreviations' : "Look here to get your J9 database",
2121
'Citation' : "Citation are special, here is how they are handled",
22-
'Record' : "The thing RecordCollections are made of",
22+
'Record' : "What RecordCollections are made of",
2323
'RecordCollection' : "Where all the stuff happens, look here if you want to make things",
2424
}
2525

26+
singleFileYAML = """---
27+
layout: page
28+
title: ""
29+
author:
30+
- name: Reid McIlroy-Young
31+
department:
32+
affiliation: University of Waterloo, Waterloo ON, Canada
33+
email: rmcilroy@uwaterloo.ca
34+
- name: John McLevey
35+
affiliation: University of Waterloo, Waterloo ON, Canada
36+
email: john.mclevey@uwaterloo.ca
37+
shorttitle: metaknowledge
38+
search_omit: true
39+
---
40+
"""
41+
2642
def makeBlurb(name):
2743
if name in blurbDict:
2844
return blurbDict[name]
2945
else:
3046
raise RuntimeError("{} needs a blurb".format(name))
3147

3248

33-
def makeHeader(title, excerpt, tags = (), weight = 10, layout = "doc"):
34-
return """---
49+
def makeHeader(title, excerpt, tags = (), weight = 10, layout = "doc", singleFile = False):
50+
if singleFile:
51+
s = """\n---\n<a name="{0}"></a>\n""".format(title)
52+
else:
53+
s = """---
3554
layout: {4}
3655
title: {0}
3756
categories: docs
@@ -41,10 +60,12 @@ def makeHeader(title, excerpt, tags = (), weight = 10, layout = "doc"):
4160
---
4261
<a name="{0}"></a>
4362
""".format(title, excerpt, ', '.join(tags), weight, layout)
63+
return s
4464

4565
def argumentParser():
4666
parser = argparse.ArgumentParser(description="A simple script to genrate docs for metaknowledge")
4767
parser.add_argument("-dir", "-d", default = os.path.normpath('.') ,nargs='?', help = 'Directory to write files to')
68+
parser.add_argument("-single", "-s", action = 'store_true', default = False ,help = 'Write to only one file.')
4869
return parser.parse_args()
4970

5071
def getLineNumber(objTuple):
@@ -71,12 +92,18 @@ def cleanargs(obj, basic = False):
7192
def makeUrls(s):
7293
return "[{0}]({{{{ site.baseurl }}}}{{% post_url /docs/{1}{2} %}}#{3})".format(s.group(1), docsPrefix, s.group(2), s.group(3))
7394

74-
def cleanedDoc(obj, lvl):
95+
def makeSingleFileUrls(s):
96+
return "[{0}](#{1})".format(s.group(1), s.group(3))
97+
98+
def cleanedDoc(obj, lvl, singleFile = False):
7599
ds = inspect.getdoc(obj)
76100
lns = ds.split('\n')
77101
nds = ''
78102
for line in lns:
79-
line = re.sub(r"\[(\S+)\]\(\#(\S+)\.(\S+)\)", makeUrls, line, count = 99)
103+
if singleFile:
104+
line = re.sub(r"\[(\S+)\]\(\#(\S+)\.(\S+)\)", makeSingleFileUrls, line, count = 99)
105+
else:
106+
line = re.sub(r"\[(\S+)\]\(\#(\S+)\.(\S+)\)", makeUrls, line, count = 99)
80107
if len(line) < 1:
81108
nds += '\n'
82109
elif line[0] == '#':
@@ -92,8 +119,11 @@ def cleanedDoc(obj, lvl):
92119
nds += line + '\n'
93120
return '{}\n\n'.format(nds)
94121

95-
def makeTitle(module, name, args = ''):
96-
s = '<a name="{1}"></a><small>{0}</small>**[<ins>{1}</ins>]({{{{ site.baseurl }}}}{{{{ page.url }}}}#{1})**{2}:\n\n'.format(module, name, args)
122+
def makeTitle(module, name, args = '', singleFile = False):
123+
if singleFile:
124+
s = '<a name="{1}"></a><small>{0}</small>**[<ins>{1}</ins>](#{1})**{2}:\n\n'.format(module, name, args)
125+
else:
126+
s = '<a name="{1}"></a><small>{0}</small>**[<ins>{1}</ins>]({{{{ site.baseurl }}}}{{{{ page.url }}}}#{1})**{2}:\n\n'.format(module, name, args)
97127
return s
98128

99129
def makeLine():
@@ -109,34 +139,42 @@ def makeLine():
109139
]
110140
return('<hr style="{}">'.format(''.join(style)))
111141

112-
def makeTable(entries, header = '', prefix = ''):
142+
def makeTable(entries, header = '', prefix = '', withBlurbs = False, bigTable = False):
113143
ents = []
114144
if prefix:
115145
prefix = prefix + '.'
116146
for e in entries:
117-
ents.append("""<li><article><a href="#{0}"><b>{0}</b>{1}</a></article></li>""".format(e[0], cleanargs(e[1], basic = True), prefix))
147+
if withBlurbs:
148+
ents.append("""<li><article><a href="#{0}"><b>{0}</b><span class="excerpt">{1}</span></a></article></li>""".format(e, blurbDict[e]))
149+
elif bigTable:
150+
if e[2] is None:
151+
ents.append("""<li><article><a href="#{0}"><b>{0}</b>{1}</a></article></li>""".format(e[0], cleanargs(e[1], basic = True), prefix))
152+
else:
153+
ents.append("""<li><article><a href="#{0}"><small>{2}</small>.<b>{0}</b>{1}</a></article></li>""".format(e[0], cleanargs(e[1], basic = True), e[2]))
154+
else:
155+
ents.append("""<li><article><a href="#{0}"><b>{0}</b>{1}</a></article></li>""".format(e[0], cleanargs(e[1], basic = True), prefix))
118156
s = """{}\n\n<ul class="post-list">\n{}\n</ul>\n""".format(header,'\n'.join(ents))
119157
return s
120158

121-
def writeFunc(fn, f, prefix = '', level = 5):
159+
def writeFunc(fn, f, prefix = '', level = 5, singleFile = False):
122160
f.write(makeLine() + "\n\n")
123-
f.write(makeTitle(prefix, fn[0], cleanargs(fn[1])))
161+
f.write(makeTitle(prefix, fn[0], cleanargs(fn[1]), singleFile = singleFile))
124162
try:
125-
f.write(cleanedDoc(fn[1], lvl = level))
163+
f.write(cleanedDoc(fn[1], lvl = level, singleFile = singleFile))
126164
except AttributeError:
127165
f.write("# Needs to be written\n\n")
128166
print("\033[93m{0}{1} had no docs\033[0m".format(prefix, fn[0]))
129167

130-
def writeClass(cl, f, prefix = '', level = 4):
131-
f.write(makeTitle(prefix, cl[0], cleanargs(cl[1].__init__)))
168+
def writeClass(cl, f, prefix = '', level = 4, singleFile = False):
169+
f.write(makeTitle(prefix, cl[0], cleanargs(cl[1].__init__), singleFile = singleFile))
132170
try:
133-
f.write(cleanedDoc(cl[1], lvl = level))
171+
f.write(cleanedDoc(cl[1], lvl = level, singleFile = singleFile))
134172
except AttributeError:
135173
f.write("# Needs to be written\n\n")
136174
print("\033[93m{0}{1} had no docs\033[0m".format(prefix, cl[0]))
137175

138-
def proccessClass(cl, f):
139-
writeClass(cl, f)
176+
def proccessClass(cl, f, singleFile = False):
177+
writeClass(cl, f, singleFile = singleFile)
140178
baseMems = inspect.getmembers(cl[1].__bases__[0])
141179
funcs = []
142180
for m in sorted(inspect.getmembers(cl[1]), key = getLineNumber):
@@ -146,23 +184,30 @@ def proccessClass(cl, f):
146184
funcs.append(m)
147185
f.write(makeTable(funcs, prefix = cl[0], header = "The {} class has the following methods:".format(cl[0])))
148186
for m in funcs:
149-
writeFunc(m, f, prefix = '{}.'.format(cl[0]))
187+
writeFunc(m, f, prefix = '{}.'.format(cl[0], singleFile = singleFile))
150188

151-
def writeClassFile(name, typ):
189+
def writeClassFile(name, typ, targetFile = None, singleFile = False):
152190
fname = docsPrefix + "{}.md".format(name)
153-
f = open(fname, 'w')
154-
f.write(makeHeader(name, makeBlurb(name), tags = ["class"], weight = 2))
155-
proccessClass((name, typ), f)
156-
f.write("\n{% include docsFooter.md %}")
157-
f.close()
191+
if targetFile is not None:
192+
f = targetFile
193+
else:
194+
f = open(fname, 'w')
195+
f.write(makeHeader(name, makeBlurb(name), tags = ["class"], weight = 2, singleFile = singleFile))
196+
proccessClass((name, typ), f, singleFile = singleFile)
197+
if targetFile is None:
198+
f.write("\n{% include docsFooter.md %}")
199+
f.close()
158200

159-
def writeModuleFile(mod):
201+
def writeModuleFile(mod, targetFile = None, singleFile = False):
160202
fname = docsPrefix + "{}.md".format(mod)
161-
f = open(fname, 'w')
162-
f.write(makeHeader(mod, makeBlurb(mod), tags = ["module"], weight = 3))
203+
if targetFile is not None:
204+
f = targetFile
205+
else:
206+
f = open(fname, 'w')
207+
f.write(makeHeader(mod, makeBlurb(mod), tags = ["module"], weight = 3, singleFile = singleFile))
163208
f.write('\n# [{0}]({{{{ site.baseurl }}}}{{{{ page.url }}}}#{0})\n\n'.format(mod))
164209
module = importlib.import_module('metaknowledge.{}'.format(mod))
165-
f.write(cleanedDoc(module, 3) + '\n\n')
210+
f.write(cleanedDoc(module, 3, singleFile = singleFile) + '\n\n')
166211
funcs = []
167212
for m in sorted(inspect.getmembers(module, predicate = inspect.isfunction), key = getLineNumber):
168213
if inspect.isbuiltin(m[1]) or m[0][0] == '_':
@@ -173,17 +218,22 @@ def writeModuleFile(mod):
173218
f.write(makeTable(funcs, prefix = mod, header = "The {} module provides the following functions:".format(mod)))
174219
for fn in funcs:
175220
writeFunc(fn, f, prefix = "{}.".format(mod))
176-
f.write("\n{% include docsFooter.md %}")
177-
f.close()
178-
179-
def writeMainBody(funcs, vrs, exceptions):
180-
f = open(docsPrefix + "overview.md", 'w')
181-
f.write(makeHeader("Overview", "The metaknowledge Package, a quick tour", tags = ["main"], weight = 0, layout = "doc"))
182-
f.write(cleanedDoc(metaknowledge, 3) + '\n\n')
183-
f.write("\n{% include docsFooter.md %}")
184-
f.close()
185-
f = open(docsPrefix + "metaknowledge.md", 'w')
186-
f.write(makeHeader("Functions", "The metaknowledge functions, for filtering reading and writing graphs", tags = ["functions"], weight = 1, layout = "doc"))
221+
if targetFile is None:
222+
f.write("\n{% include docsFooter.md %}")
223+
f.close()
224+
225+
def writeMainBody(funcs, vrs, exceptions, targetFile = None, singleFile = False):
226+
if targetFile:
227+
f = targetFile
228+
else:
229+
f = open(docsPrefix + "overview.md", 'w')
230+
f.write(makeHeader("Overview", "The metaknowledge Package, a quick tour", tags = ["main"], weight = 0, layout = "doc", singleFile = singleFile))
231+
f.write(cleanedDoc(metaknowledge, 3, singleFile = singleFile) + '\n\n')
232+
if targetFile is None:
233+
f.write("\n{% include docsFooter.md %}")
234+
f.close()
235+
f = open(docsPrefix + "metaknowledge.md", 'w')
236+
f.write(makeHeader("Base Functions", "The metaknowledge functions, for filtering reading and writing graphs", tags = ["functions"], weight = 1, layout = "doc", singleFile = singleFile))
187237
f.write(makeTable(funcs, header = "The functions provided by metaknowledge are:"))
188238
for fnc in funcs:
189239
writeFunc(fnc, f)
@@ -194,8 +244,9 @@ def writeMainBody(funcs, vrs, exceptions):
194244
else:
195245
f.write(makeLine() + "\n\n")
196246
proccessClass(excpt, f)
197-
f.write("\n{% include docsFooter.md %}")
198-
f.close()
247+
if targetFile is None:
248+
f.write("\n{% include docsFooter.md %}")
249+
f.close()
199250

200251
def main(args):
201252
wDir = os.path.expanduser(os.path.normpath(args.dir))
@@ -223,11 +274,39 @@ def main(args):
223274
funcs.append(m)
224275
else:
225276
vrs.append(m)
226-
writeMainBody(funcs, vrs, exceptions)
277+
if args.single:
278+
f = open("metaknowledgeFull.md",'w')
279+
f.write(singleFileYAML)
280+
f.write(makeTable([c[0] for c in classes] + documentedModules, header = "The classes and modules of metaknowledge are:", withBlurbs = True))
281+
single = True
282+
bigTableEntries = [(f[0], f[1], None) for f in funcs]
283+
for cls in classes:
284+
baseMems = inspect.getmembers(cls[1].__bases__[0])
285+
for m in sorted(inspect.getmembers(cls[1]), key = getLineNumber):
286+
if m[0][0] == '_' or m in baseMems:
287+
pass
288+
elif inspect.isfunction(m[1]):
289+
bigTableEntries.append((m[0], m[1], cls[0]))
290+
for mod in documentedModules:
291+
module = importlib.import_module('metaknowledge.{}'.format(mod))
292+
for m in sorted(inspect.getmembers(module, predicate = inspect.isfunction), key = getLineNumber):
293+
if inspect.isbuiltin(m[1]) or m[0][0] == '_':
294+
pass
295+
elif inspect.isfunction(m[1]):
296+
bigTableEntries.append((m[0], m[1], mod))
297+
print(len(bigTableEntries))
298+
f.write(makeTable(bigTableEntries, header = '<a name="fulllist"></a>All the functions and methods of metaknowledge are as follows:', bigTable = True))
299+
else:
300+
single = False
301+
f = None
302+
writeMainBody(funcs, vrs, exceptions, targetFile = f, singleFile = single)
227303
for cls in classes:
228-
writeClassFile(*cls)
304+
writeClassFile(*cls, targetFile = f, singleFile = single)
229305
for mod in documentedModules:
230-
writeModuleFile(mod)
306+
writeModuleFile(mod, targetFile = f, singleFile = single)
307+
if args.single:
308+
f.write("\n{% include docsFooter.md %}")
309+
f.close
231310

232311
def mkDocs():
233312
args = argumentParser()

metaknowledge/citation.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,27 @@ def getID(self):
167167
else:
168168
return "{0}, {1}, {2}".format(self.author, self.year, self.journal)
169169

170+
def allButDOI(self):
171+
"""
172+
Returns a string of the normalized values from the Citation excluding the DOI number. Equivalent to getting the ID with [`getID()`](#Citation.getID) then appending the extra values from [`getExtra()`](#Citation.getExtra) and then removing the substring containing the DOI number.
173+
174+
# Returns
175+
176+
`str`
177+
178+
> A string containing the data of the Citation.
179+
"""
180+
extraTags = ['V', 'P', 'misc']
181+
s = self.getID()
182+
extras = []
183+
for tag in extraTags:
184+
if getattr(self, tag):
185+
extras.append(str(getattr(self, tag)))
186+
if len(extras) > 0:
187+
return "{0}, {1}".format(s, ', '.join(extras))
188+
else:
189+
return s
190+
170191
def getExtra(self):
171192
"""
172193
Returns any V, P, DOI or misc values as a string. These are all the values not returned by [`getID()`](#Citation.getID).
@@ -176,7 +197,7 @@ def getExtra(self):
176197
`str`
177198
178199
> A string containing the data not in the ID of the Citation.
179-
"""
200+
"""
180201
extraTags = ['V', 'P', 'DOI', 'misc']
181202
retVal = ""
182203
for tag in extraTags:

0 commit comments

Comments
 (0)