Skip to content
This repository
Browse code

utf-8, allow extracting the whole library

  • Loading branch information...
commit 72dcfefaa13da9df97ae92256b04701b9255301c 1 parent 1585366
Chris Johnson-Roberson authored
43  chrome/content/papermachines/papermachines.js
@@ -603,24 +603,29 @@ Zotero.PaperMachines = {
603 603
 	},
604 604
 	traverseItemGroup: function (itemGroup) {
605 605
 		var itemGroups = [];
606  
-		itemGroups.push(itemGroup);
607  
-		if ("isCollection" in itemGroup && itemGroup.isCollection()) {
608  
-			var currentCollection = ("ref" in itemGroup) ? itemGroup.ref : itemGroup;
609  
-			if (currentCollection.hasChildCollections()) {
610  
-				var children = currentCollection.getChildCollections();
611  
-				for (var i in children) {
612  
-					itemGroups.push(Zotero.PaperMachines.traverseItemGroup(children[i]));
613  
-				}
  606
+		if ("isLibrary" in itemGroup && itemGroup.isLibrary()) {
  607
+			if (itemGroup.id == "L") {
  608
+				var collectionKeys = Zotero.DB.columnQuery("SELECT key from collections WHERE libraryID IS NULL;");
  609
+				itemGroups = collectionKeys.map(function(d) { return Zotero.Collections.getByLibraryAndKey(null, d); });
614 610
 			}
615  
-		} else if (itemGroup.isGroup()) {
616  
-			if (itemGroup.ref.hasCollections()) {
617  
-				var children = itemGroup.ref.getCollections();
618  
-				for (var i in children) {
619  
-					itemGroups.push(Zotero.PaperMachines.traverseItemGroup(children[i]));
620  
-				}				
  611
+		} else {
  612
+			if ("isCollection" in itemGroup && itemGroup.isCollection()) {
  613
+				itemGroups.push(itemGroup);
  614
+				var currentCollection = ("ref" in itemGroup) ? itemGroup.ref : itemGroup;
  615
+				if (currentCollection.hasChildCollections()) {
  616
+					var children = currentCollection.getChildCollections();
  617
+					for (var i in children) {
  618
+						itemGroups.push(Zotero.PaperMachines.traverseItemGroup(children[i]));
  619
+					}
  620
+				}
  621
+			} else if (itemGroup.isGroup()) {
  622
+				if (itemGroup.ref.hasCollections()) {
  623
+					var children = itemGroup.ref.getCollections();
  624
+					for (var i in children) {
  625
+						itemGroups.push(Zotero.PaperMachines.traverseItemGroup(children[i]));
  626
+					}				
  627
+				}
621 628
 			}
622  
-		} else if (itemGroup.isLibrary()) {
623  
-			// TODO
624 629
 		}
625 630
 		return itemGroups;
626 631
 	},
@@ -698,13 +703,13 @@ Zotero.PaperMachines = {
698 703
 	},
699 704
 	getItemGroupID: function (itemGroup) {
700 705
 		if (!itemGroup) return null;
701  
-		if (typeof itemGroup.isCollection === "function" && "isCollection" in itemGroup && itemGroup.isCollection()) {
  706
+		if ("isCollection" in itemGroup && itemGroup.isCollection()) {
702 707
 			if (itemGroup.hasOwnProperty("ref")) {
703 708
 				return (itemGroup.ref.libraryID != null ? itemGroup.ref.libraryID.toString() : "") + "C" + itemGroup.ref.id.toString();				
704 709
 			} else {
705 710
 				return (itemGroup.libraryID != null ? itemGroup.libraryID.toString() : "") + "C" + itemGroup.id.toString();								
706 711
 			}
707  
-		} else if (typeof itemGroup.isGroup === "function" && itemGroup.isGroup()) {
  712
+		} else if ("isGroup" in itemGroup && itemGroup.isGroup()) {
708 713
 			return itemGroup.ref.libraryID;
709 714
 		} else {
710 715
 			return itemGroup.id;
@@ -713,6 +718,8 @@ Zotero.PaperMachines = {
713 718
 	getGroupByID: function (id) {
714 719
 		if (id.indexOf("C") != -1) {
715 720
 			return Zotero.Collections.get(id.split("C")[1]);
  721
+		} else if (id == "L") {
  722
+			return ZoteroPane.collectionsView._dataItems[0][0];
716 723
 		}
717 724
 	},
718 725
 	getNameOfGroup: function (id) {
1  chrome/content/papermachines/processors/templates/dbpedia.html
... ...
@@ -1,6 +1,7 @@
1 1
 <!DOCTYPE html>
2 2
 <html>
3 3
 <head>
  4
+	<meta charset="UTF-8" />
4 5
 	<title>DBPedia: COLLECTION_NAME</title>
5 6
     <script type="text/javascript" src="support/d3.v2.js"></script>
6 7
 	<script type="text/javascript">
3  chrome/content/papermachines/processors/templates/extract.html
... ...
@@ -1,7 +1,8 @@
1 1
 <!DOCTYPE html>
2 2
 <html>
3 3
 <head>
4  
-<title>Extracting: COLLECTION_NAME</title>
  4
+	<meta charset="UTF-8" />
  5
+	<title>Extracting: COLLECTION_NAME</title>
5 6
 </head>
6 7
 <body>
7 8
 <div>Extracted SUCCEEDED out of TOTAL new texts. This window can now be closed.</div>
1  chrome/content/papermachines/processors/templates/geoparse.html
... ...
@@ -1,6 +1,7 @@
1 1
 <!DOCTYPE html>
2 2
 <html>
3 3
   <head>
  4
+  <meta charset="UTF-8" />
4 5
     <title>Geoparser: COLLECTION_NAME</title>
5 6
     <script type="text/javascript" src="support/d3.v2.js"></script>
6 7
     <script type="text/javascript" src="support/html5slider.js"></script>
1  chrome/content/papermachines/processors/templates/mallet_black.html
... ...
@@ -1,6 +1,7 @@
1 1
 <!DOCTYPE html>
2 2
 <html>
3 3
   <head>
  4
+  <meta charset="UTF-8" />
4 5
     <title>Streamgraph</title>
5 6
     <script type="text/javascript" src="support/d3.v2.js"></script>
6 7
     <script type="text/javascript" src="support/innersvg.js"></script>
3  chrome/content/papermachines/processors/templates/mallet_classify-file.html
... ...
@@ -1,7 +1,8 @@
1 1
 <!DOCTYPE html>
2 2
 <html>
3 3
 <head>
4  
-<title>Classifier: COLLECTION_NAME</title>
  4
+	<meta charset="UTF-8" />
  5
+	<title>Classifier: COLLECTION_NAME</title>
5 6
 </head>
6 7
 <body>
7 8
 <pre>CLASSIFIED</pre>
1  chrome/content/papermachines/processors/templates/mallet_lda.html
... ...
@@ -1,6 +1,7 @@
1 1
 <!DOCTYPE html>
2 2
 <html>
3 3
   <head>
  4
+  <meta charset="UTF-8" />
4 5
     <title>Topic Modeling: COLLECTION_NAME</title>
5 6
     <script type="text/javascript" src="support/d3.v2.js"></script>
6 7
     <script type="text/javascript" src="support/innersvg.js"></script>
3  chrome/content/papermachines/processors/templates/mallet_lda_MI.html
... ...
@@ -1,7 +1,8 @@
1 1
 <!DOCTYPE html>
2 2
 <html>
3 3
 <head>
4  
-<title>Mutual Information: COLLECTION_NAME</title>
  4
+	<meta charset="UTF-8" />
  5
+	<title>Mutual Information: COLLECTION_NAME</title>
5 6
     <script type="text/javascript" src="support/d3.v2.js"></script>
6 7
 	<script type="text/javascript" src="support/html5slider.js"></script>
7 8
 	<script type="text/javascript">
1  chrome/content/papermachines/processors/templates/mallet_train-classifier.html
... ...
@@ -1,6 +1,7 @@
1 1
 <!DOCTYPE html>
2 2
 <html>
3 3
 <head>
  4
+<meta charset="UTF-8" />
4 5
 <title>Classifier: COLLECTION_NAME</title>
5 6
 </head>
6 7
 <body>
7  chrome/content/papermachines/processors/templates/phrasenet.html
... ...
@@ -1,8 +1,9 @@
1 1
 <html>
2 2
 <head>
3  
-    <title>Phrase Net: COLLECTION_NAME</title>
4  
-<script src="support/d3.v2.js"></script>
5  
-<script src="support/d3.layout.cloud.js"></script>
  3
+  <meta charset="UTF-8" />
  4
+  <title>Phrase Net: COLLECTION_NAME</title>
  5
+  <script src="support/d3.v2.js"></script>
  6
+  <script src="support/d3.layout.cloud.js"></script>
6 7
 <style type="text/css">
7 8
 body {
8 9
   font: 12pt sans-serif;
5  chrome/content/papermachines/processors/templates/wordcloud.html
... ...
@@ -1,9 +1,10 @@
1 1
 <!DOCTYPE html>
2 2
 <html>
3 3
   <head>
  4
+  <meta charset="UTF-8" />
4 5
     <title>Word Cloud: COLLECTION_NAME</title>
5  
-<script src="support/d3.v2.js"></script>
6  
-<script src="support/d3.layout.cloud.js"></script>
  6
+  <script src="support/d3.v2.js"></script>
  7
+  <script src="support/d3.layout.cloud.js"></script>
7 8
 </head>
8 9
 <body>
9 10
 <script>
7  chrome/content/papermachines/processors/templates/wordcloud_multiple.html
... ...
@@ -1,9 +1,10 @@
1 1
 <!DOCTYPE html>
2 2
 <html>
3 3
   <head>
4  
-    <title>Multiple Word Clouds: COLLECTION_NAME</title>
5  
-<script src="support/d3.v2.js"></script>
6  
-<script src="support/d3.layout.cloud.js"></script>
  4
+  <meta charset="UTF-8" />
  5
+  <title>Multiple Word Clouds: COLLECTION_NAME</title>
  6
+  <script src="support/d3.v2.js"></script>
  7
+  <script src="support/d3.layout.cloud.js"></script>
7 8
 </head>
8 9
 <body>
9 10
 <script>
4  chrome/content/papermachines/processors/textprocessor.pyw
@@ -94,8 +94,8 @@ class TextProcessor:
94 94
 		try:
95 95
 			template_filename = getattr(self, "template_filename", os.path.join(self.cwd, "templates", self.name + ".html"))
96 96
 			out_filename = getattr(self, "out_filename", os.path.join(self.out_dir, self.name + self.collection + "-" + self.args_basename + ".html"))
97  
-			with file(out_filename, 'w') as outfile:
98  
-				with file(template_filename) as template:
  97
+			with codecs.open(out_filename, 'w', encoding='utf-8') as outfile:
  98
+				with codecs.open(template_filename, 'r', encoding='utf-8') as template:
99 99
 					template_str = template.read()
100 100
 					for k, v in params.iteritems():
101 101
 						template_str = template_str.replace(k, v)
2  install.rdf
@@ -5,7 +5,7 @@
5 5
 	<Description about="urn:mozilla:install-manifest">
6 6
 		<em:id>papermachines@chrisjr.org</em:id>
7 7
 		<em:name>Paper Machines</em:name>
8  
-		<em:version>0.1.7</em:version>
  8
+		<em:version>0.1.8</em:version>
9 9
 		<em:description>A Zotero extension for analysis and visualization in the digital humanities.</em:description>
10 10
 		<em:creator>Chris Johnson-Roberson</em:creator>
11 11
 		<em:unpack>true</em:unpack>

0 notes on commit 72dcfef

Please sign in to comment.
Something went wrong with that request. Please try again.