Permalink
Browse files

utf-8, allow extracting the whole library

  • Loading branch information...
corajr committed Sep 17, 2012
1 parent 1585366 commit 72dcfefaa13da9df97ae92256b04701b9255301c
@@ -603,24 +603,29 @@ Zotero.PaperMachines = {
},
traverseItemGroup: function (itemGroup) {
var itemGroups = [];
- itemGroups.push(itemGroup);
- if ("isCollection" in itemGroup && itemGroup.isCollection()) {
- var currentCollection = ("ref" in itemGroup) ? itemGroup.ref : itemGroup;
- if (currentCollection.hasChildCollections()) {
- var children = currentCollection.getChildCollections();
- for (var i in children) {
- itemGroups.push(Zotero.PaperMachines.traverseItemGroup(children[i]));
- }
+ if ("isLibrary" in itemGroup && itemGroup.isLibrary()) {
+ if (itemGroup.id == "L") {
+ var collectionKeys = Zotero.DB.columnQuery("SELECT key from collections WHERE libraryID IS NULL;");
+ itemGroups = collectionKeys.map(function(d) { return Zotero.Collections.getByLibraryAndKey(null, d); });
}
- } else if (itemGroup.isGroup()) {
- if (itemGroup.ref.hasCollections()) {
- var children = itemGroup.ref.getCollections();
- for (var i in children) {
- itemGroups.push(Zotero.PaperMachines.traverseItemGroup(children[i]));
- }
+ } else {
+ if ("isCollection" in itemGroup && itemGroup.isCollection()) {
+ itemGroups.push(itemGroup);
+ var currentCollection = ("ref" in itemGroup) ? itemGroup.ref : itemGroup;
+ if (currentCollection.hasChildCollections()) {
+ var children = currentCollection.getChildCollections();
+ for (var i in children) {
+ itemGroups.push(Zotero.PaperMachines.traverseItemGroup(children[i]));
+ }
+ }
+ } else if (itemGroup.isGroup()) {
+ if (itemGroup.ref.hasCollections()) {
+ var children = itemGroup.ref.getCollections();
+ for (var i in children) {
+ itemGroups.push(Zotero.PaperMachines.traverseItemGroup(children[i]));
+ }
+ }
}
- } else if (itemGroup.isLibrary()) {
- // TODO
}
return itemGroups;
},
@@ -698,13 +703,13 @@ Zotero.PaperMachines = {
},
getItemGroupID: function (itemGroup) {
if (!itemGroup) return null;
- if (typeof itemGroup.isCollection === "function" && "isCollection" in itemGroup && itemGroup.isCollection()) {
+ if ("isCollection" in itemGroup && itemGroup.isCollection()) {
if (itemGroup.hasOwnProperty("ref")) {
return (itemGroup.ref.libraryID != null ? itemGroup.ref.libraryID.toString() : "") + "C" + itemGroup.ref.id.toString();
} else {
return (itemGroup.libraryID != null ? itemGroup.libraryID.toString() : "") + "C" + itemGroup.id.toString();
}
- } else if (typeof itemGroup.isGroup === "function" && itemGroup.isGroup()) {
+ } else if ("isGroup" in itemGroup && itemGroup.isGroup()) {
return itemGroup.ref.libraryID;
} else {
return itemGroup.id;
@@ -713,6 +718,8 @@ Zotero.PaperMachines = {
getGroupByID: function (id) {
if (id.indexOf("C") != -1) {
return Zotero.Collections.get(id.split("C")[1]);
+ } else if (id == "L") {
+ return ZoteroPane.collectionsView._dataItems[0][0];
}
},
getNameOfGroup: function (id) {
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
+ <meta charset="UTF-8" />
<title>DBPedia: COLLECTION_NAME</title>
<script type="text/javascript" src="support/d3.v2.js"></script>
<script type="text/javascript">
@@ -1,7 +1,8 @@
<!DOCTYPE html>
<html>
<head>
-<title>Extracting: COLLECTION_NAME</title>
+ <meta charset="UTF-8" />
+ <title>Extracting: COLLECTION_NAME</title>
</head>
<body>
<div>Extracted SUCCEEDED out of TOTAL new texts. This window can now be closed.</div>
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
+ <meta charset="UTF-8" />
<title>Geoparser: COLLECTION_NAME</title>
<script type="text/javascript" src="support/d3.v2.js"></script>
<script type="text/javascript" src="support/html5slider.js"></script>
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
+ <meta charset="UTF-8" />
<title>Streamgraph</title>
<script type="text/javascript" src="support/d3.v2.js"></script>
<script type="text/javascript" src="support/innersvg.js"></script>
@@ -1,7 +1,8 @@
<!DOCTYPE html>
<html>
<head>
-<title>Classifier: COLLECTION_NAME</title>
+ <meta charset="UTF-8" />
+ <title>Classifier: COLLECTION_NAME</title>
</head>
<body>
<pre>CLASSIFIED</pre>
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
+ <meta charset="UTF-8" />
<title>Topic Modeling: COLLECTION_NAME</title>
<script type="text/javascript" src="support/d3.v2.js"></script>
<script type="text/javascript" src="support/innersvg.js"></script>
@@ -1,7 +1,8 @@
<!DOCTYPE html>
<html>
<head>
-<title>Mutual Information: COLLECTION_NAME</title>
+ <meta charset="UTF-8" />
+ <title>Mutual Information: COLLECTION_NAME</title>
<script type="text/javascript" src="support/d3.v2.js"></script>
<script type="text/javascript" src="support/html5slider.js"></script>
<script type="text/javascript">
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
+<meta charset="UTF-8" />
<title>Classifier: COLLECTION_NAME</title>
</head>
<body>
@@ -1,8 +1,9 @@
<html>
<head>
- <title>Phrase Net: COLLECTION_NAME</title>
-<script src="support/d3.v2.js"></script>
-<script src="support/d3.layout.cloud.js"></script>
+ <meta charset="UTF-8" />
+ <title>Phrase Net: COLLECTION_NAME</title>
+ <script src="support/d3.v2.js"></script>
+ <script src="support/d3.layout.cloud.js"></script>
<style type="text/css">
body {
font: 12pt sans-serif;
@@ -1,9 +1,10 @@
<!DOCTYPE html>
<html>
<head>
+ <meta charset="UTF-8" />
<title>Word Cloud: COLLECTION_NAME</title>
-<script src="support/d3.v2.js"></script>
-<script src="support/d3.layout.cloud.js"></script>
+ <script src="support/d3.v2.js"></script>
+ <script src="support/d3.layout.cloud.js"></script>
</head>
<body>
<script>
@@ -1,9 +1,10 @@
<!DOCTYPE html>
<html>
<head>
- <title>Multiple Word Clouds: COLLECTION_NAME</title>
-<script src="support/d3.v2.js"></script>
-<script src="support/d3.layout.cloud.js"></script>
+ <meta charset="UTF-8" />
+ <title>Multiple Word Clouds: COLLECTION_NAME</title>
+ <script src="support/d3.v2.js"></script>
+ <script src="support/d3.layout.cloud.js"></script>
</head>
<body>
<script>
@@ -94,8 +94,8 @@ class TextProcessor:
try:
template_filename = getattr(self, "template_filename", os.path.join(self.cwd, "templates", self.name + ".html"))
out_filename = getattr(self, "out_filename", os.path.join(self.out_dir, self.name + self.collection + "-" + self.args_basename + ".html"))
- with file(out_filename, 'w') as outfile:
- with file(template_filename) as template:
+ with codecs.open(out_filename, 'w', encoding='utf-8') as outfile:
+ with codecs.open(template_filename, 'r', encoding='utf-8') as template:
template_str = template.read()
for k, v in params.iteritems():
template_str = template_str.replace(k, v)
View
@@ -5,7 +5,7 @@
<Description about="urn:mozilla:install-manifest">
<em:id>papermachines@chrisjr.org</em:id>
<em:name>Paper Machines</em:name>
- <em:version>0.1.7</em:version>
+ <em:version>0.1.8</em:version>
<em:description>A Zotero extension for analysis and visualization in the digital humanities.</em:description>
<em:creator>Chris Johnson-Roberson</em:creator>
<em:unpack>true</em:unpack>

0 comments on commit 72dcfef

Please sign in to comment.