-
Notifications
You must be signed in to change notification settings - Fork 0
/
pivot.py
425 lines (347 loc) · 16.5 KB
/
pivot.py
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# -*- coding: utf-8 -*-
import sys
sys.path.insert(0,'.')
import xml, traceback, os, re, codecs
from xml.dom import minidom
from datetime import datetime
from deepzoom import *
testentry = """<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:excerpt="http://wordpress.org/export/1.0/excerpt/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:wp="http://wordpress.org/export/1.0/"
xmlns:atom="http://www.w3.org/2005/Atom"
>
<items>
<item>
<title>Talking with Kingsley Idehen about mastering your own search index</title>
<link>http://blog.jonudell.net/2009/09/09/talking-with-kingsley-idehen-about-mastering-your-own-search-index/</link>
<pubDate>Wed, 09 Sep 2009 14:21:49 +0000</pubDate>
<dc:creator><![CDATA[Jon Udell]]></dc:creator>
<category><![CDATA[Uncategorized]]></category>
<category domain="category" nicename="uncategorized"><![CDATA[Uncategorized]]></category>
<category domain="tag"><![CDATA[goodrelations]]></category>
<category domain="tag" nicename="goodrelations"><![CDATA[goodrelations]]></category>
<category domain="tag"><![CDATA[kingsleyidehen]]></category>
<category domain="tag" nicename="kingsleyidehen"><![CDATA[kingsleyidehen]]></category>
<category domain="tag"><![CDATA[rdfa]]></category>
<category domain="tag" nicename="rdfa"><![CDATA[rdfa]]></category>
<category domain="tag"><![CDATA[seo]]></category>
<category domain="tag" nicename="seo"><![CDATA[seo]]></category>
<guid isPermaLink="false">http://blog.jonudell.net/?p=1868</guid>
<description></description>
<content:encoded><![CDATA[<p>
Kingsley Idehen's vision of a web of linked data long predates the <a href="http://robots.infoworld.com/article/03/05/23/21FEinnovidehen_1.html">recognition</a> I accorded him in 2003. He's seen the big picture for a very long time, and has been driving toward it consistently. Over the years we've had <a href="http://jonudell.net/udell/2006-04-27-a-conversation-with-kingsley-idehen-about-open-source-virtuoso.html">conversations</a> in which I've always wound up saying: "Yes, OK, but how will we get people to create this web of linked data that we want to navigate and query?"
</p>
<p>
To navigate and query a web of linked data you need, obviously, mechanisms by which to do the navigation and the querying. That's never been the problem. Technologists love to figure such things out. But we've spectacularly failed to help people create that web of linked data in the first place. I don't know if the approach Kingsley Idehen sketches in this week's podcast will succeed. But it feels right, and I love his tagline: "Be the master of your own index."
</p>
]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>1868</wp:post_id>
<wp:post_date>2009-09-09 09:21:49</wp:post_date>
<wp:post_date_gmt>2009-09-09 14:21:49</wp:post_date_gmt>
<wp:comment_status>open</wp:comment_status>
<wp:ping_status>open</wp:ping_status>
<wp:post_name>talking-with-kingsley-idehen-about-mastering-your-own-search-index</wp:post_name>
<wp:status>publish</wp:status>
<wp:post_parent>0</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
<wp:post_type>post</wp:post_type>
<wp:post_password></wp:post_password>
<wp:is_sticky>0</wp:is_sticky>
<wp:postmeta>
<wp:meta_key>_edit_last</wp:meta_key>
<wp:meta_value><![CDATA[108410]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_edit_lock</wp:meta_key>
<wp:meta_value><![CDATA[1269619136]]></wp:meta_value>
</wp:postmeta>
<wp:comment>
<wp:comment_id>132539</wp:comment_id>
<wp:comment_author><![CDATA[Manchester Solicitors]]></wp:comment_author>
<wp:comment_author_email>Hazarika@gmail.com</wp:comment_author_email>
<wp:comment_author_url>http://www.manchestersolicitors.org.uk</wp:comment_author_url>
<wp:comment_author_IP>94.197.54.134</wp:comment_author_IP>
<wp:comment_date>2010-03-16 03:48:27</wp:comment_date>
<wp:comment_date_gmt>2010-03-16 08:48:27</wp:comment_date_gmt>
<wp:comment_content><![CDATA[Hi vey nice interesting blog im from irland i found this on yahoo i found this blog very interesting good luck with it i will return to this blog soon]]></wp:comment_content>
<wp:comment_approved>spam</wp:comment_approved>
<wp:comment_type></wp:comment_type>
<wp:comment_parent>0</wp:comment_parent>
<wp:comment_user_id>0</wp:comment_user_id>
</wp:comment>
<wp:comment>
<wp:comment_id>130198</wp:comment_id>
<wp:comment_author><![CDATA[Healthcare Semantic Architectures » RDFa Links for Reference and Quick Intros]]></wp:comment_author>
<wp:comment_author_email></wp:comment_author_email>
<wp:comment_author_url>http://www.semanticarch.com/wordpress/?p=119</wp:comment_author_url>
<wp:comment_author_IP>69.89.31.189</wp:comment_author_IP>
<wp:comment_date>2009-09-18 16:24:32</wp:comment_date>
<wp:comment_date_gmt>2009-09-18 21:24:32</wp:comment_date_gmt>
<wp:comment_content><![CDATA[[...] Talking with Kingsley Idehen about mastering your own search index (jonudell.net) Categories: Ontology, RDF, RDFa, Semantic Web Tags: Comments (0) Trackbacks (0) Leave a comment Trackback [...] ]]></wp:comment_content>
<wp:comment_approved>1</wp:comment_approved>
<wp:comment_type>pingback</wp:comment_type>
<wp:comment_parent>0</wp:comment_parent>
<wp:comment_user_id>0</wp:comment_user_id>
</wp:comment>
</item>
<item>
<title>A conversation with Allen Wirfs-Brock about the history of Smalltalk and the future of dynamic languages</title>
<link>http://blog.jonudell.net/2007/05/21/a-conversation-with-allen-wirfs-brock-about-the-history-of-smalltalk-and-the-future-of-dynamic-languages/</link>
<pubDate>Mon, 21 May 2007 15:46:57 +0000</pubDate>
<dc:creator><![CDATA[Jon Udell]]></dc:creator>
<content:encoded><![CDATA[ More than 25 years ago, Allen Wirfs-Brock created one of the early implementations of Smalltalk. He was working at Tektronix at the time, as was Ward Cunningham who became the first user of Tektronix Smalltalk. Allen later served as chief scientist of Digitalk-ParcPlace and CTO of Instantiations, then joined Microsoft four years ago. His original charter was to work on future strategies for Visual Studio, but recently -- in light of growing interest in dynamic languages at Microsot -- he's returning to his roots.
In the <a href="http://channel9.msdn.com/media/ju_wirfs-brock.mp3">latest installment</a> of my <a href="http://channel9.msdn.com/shows/Microsoft_Conversations_with_Jon_Udell">Microsoft Conversations</a> series we review the history of Smalltalk, and trace the evolution of the techniques that it (and Lisp) pioneered, from the early implementations to such modern descendants as Python and Ruby.
I'm always looking for ways to explain why dynamic programming techniques are so important, and a great explanation emerged from this conversation. A Smalltalk system is, among other things, a population of continuously evolving objects that communicate by passing messages. That same description applies to another kind of system: the Internet. I suggested -- and Allen agreed -- that this congruence is driving renewed appreciation for dynamic languages.]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>142</wp:post_id>
<wp:post_date>2007-05-21 10:46:57</wp:post_date>
<wp:post_date_gmt>2007-05-21 15:46:57</wp:post_date_gmt>
<wp:comment_status>open</wp:comment_status>
<wp:ping_status>open</wp:ping_status>
<wp:post_name>a-conversation-with-allen-wirfs-brock-about-the-history-of-smalltalk-and-the-future-of-dynamic-languages</wp:post_name>
<wp:status>publish</wp:status>
<wp:post_parent>0</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
<wp:post_type>post</wp:post_type>
<wp:post_password></wp:post_password>
<wp:is_sticky>0</wp:is_sticky>
<wp:postmeta>
<wp:meta_key>enclosure</wp:meta_key>
<wp:meta_value><![CDATA[http://channel9.msdn.com/media/ju_wirfs-brock.mp3
16136443
audio/mpeg
]]></wp:meta_value>
</wp:postmeta>
<wp:comment>
<wp:comment_id>19858</wp:comment_id>
<wp:comment_author><![CDATA[nate_combs]]></wp:comment_author>
<wp:comment_author_email>ncombs@roaringshrimp.com</wp:comment_author_email>
<wp:comment_author_url>http://scratchpad.roaringshrimp.com/</wp:comment_author_url>
<wp:comment_author_IP>68.160.59.29</wp:comment_author_IP>
<wp:comment_date>2007-05-23 21:35:59</wp:comment_date>
<wp:comment_date_gmt>2007-05-24 02:35:59</wp:comment_date_gmt>
<wp:comment_content><![CDATA[>Alan Kay in his excellent keynote speech at OOPSLA 1997 (video available here http://video.google.com/videoplay?docid=-2950949730059754521).
This link doesn't appear to be valid anymore.
I found a list of other presentations at:
http://www.quartopiano.com/Quartopiano/Croquet%20Project.html]]></wp:comment_content>
<wp:comment_approved>1</wp:comment_approved>
<wp:comment_type></wp:comment_type>
<wp:comment_parent>0</wp:comment_parent>
<wp:comment_user_id>0</wp:comment_user_id>
</wp:comment>
</item>
</items></rss>
"""
testentry = unicode(testentry, errors='ignore')
def _log(msg):
print msg
f = open('log.txt','a')
f.write('%s\n' % msg)
f.close()
def _trace_log():
f = open('log.txt','a')
traceback.print_exc(3,f)
f.close()
class PivotItem():
def __init__(self,index):
self.index = index
self.title = None
self.id = None
self.link = None
self.date = None
self.tags = None
self.comments = None
self.blurb = None
def __repr__(self):
return '<PivotItem>: %s, %s' % (self.title, self.date)
def MakeJPEG(self):
cmd = 'iecapt --url=%s --delay=1000 --out=tmp.jpg' % ( self.link )
_log(cmd)
os.system(cmd)
cmd = 'convert -quality 100 -crop 530x500+30+180 -border 1x1 -bordercolor Black tmp.jpg %s.jpg' % self.id
_log(cmd)
os.system(cmd)
def MakeDZI(self):
destination = ('%s.xml' % self.id)
source = ('%s.jpg' % self.id)
creator = ImageCreator(tile_size=256,
tile_format='jpg',
image_quality=0.95,
resize_filter='antialias')
creator.create(source, destination)
def AsXml(self):
item_xml = self._item_template()
tag_elements = ''
if len(self.tags) > 0:
for tag in self.tags:
tag_element = self._tag_template() % tag
tag_elements += tag_element
tag_elements = """<Facet Name="tag">
%s
</Facet>""" % tag_elements
dict = {
'__TITLE__': self.title,
'__ID__': str(self.index),
'__TITLE__': self.title,
'__HREF__': self.link,
'__DATE__': self.date,
'__COMMENTS__': str(self.comments),
'__DESCR__': self.blurb,
'__TAGS__': tag_elements
}
for key in dict.keys():
item_xml = item_xml.replace(key,dict[key])
return item_xml
def _tag_template(self):
return """<String Value="%s" />"""
def _item_template(self):
return """<Item Id="__ID__" Img="#__ID__" Name="__TITLE__" Href="__HREF__">
<Description>__DESCR__</Description>
<Facets>
<Facet Name="date">
<DateTime Value="__DATE__" />
</Facet>
__TAGS__
<!--
<Facet Name="yearmonth">
<String Value="__YEARMONTH__" />
</Facet>
-->
<Facet Name="comments">
<Number Value="__COMMENTS__" />
</Facet>
</Facets>
</Item>
"""
class PivotItemCollection():
def __init__(self,wp='wp.xml',testing=False,do_images=True):
self.wp = wp
self.testing = testing
self.do_images = do_images
self.xml = None
self.pivot_items_xml = ''
self.images = []
self.dzc_output = 'dzc_output'
self.blurb_max_len = 500
if self.testing:
doc = minidom.parseString(testentry)
else:
f = codecs.open(self.wp, 'r', 'utf-8')
xml = f.read()
f.close()
if xml.find('xmlns:atom="http://www.w3.org/2005/Atom"') == -1:
xml = xml.replace('xmlns:wp="http://wordpress.org/export/1.0/"', 'xmlns:wp="http://wordpress.org/export/1.0/" xmlns:atom="http://www.w3.org/2005/Atom"')
f = codecs.open(self.wp, 'w', 'utf-8')
f.write(xml)
f.close()
doc = minidom.parse(self.wp)
self.items = doc.getElementsByTagName('item')
def _extractBlurb(self,content,max):
end = min(len(content),max)
return content[0:max] + '...'
def ProcessItems(self):
i = 0
for item in self.items:
_log('item %d' % i)
try:
title = item.getElementsByTagName('title')[0].firstChild.nodeValue
title = title.replace('"','')
_log('title: ' + title)
link = item.getElementsByTagName('link')[0].firstChild.nodeValue
_log('link: ' + link)
if link.find('attachment_id') > -1:
_log('skipping attachment: ' + link)
continue
if link.find('page_id') > -1:
_log('skipping page: ' + link)
continue
id = item.getElementsByTagNameNS('http://wordpress.org/export/1.0/','post_id')[0].firstChild.nodeValue
_log('id: ' + id)
date = item.getElementsByTagNameNS('http://wordpress.org/export/1.0/','post_date')[0].firstChild.nodeValue[0:10] + 'T00:00:00-00:00'
if date.startswith('0'):
continue
categories = item.getElementsByTagName('category')
categories = [c for c in categories if len(c.attributes.keys()) > 0 ]
categories = [c for c in categories if c.getAttribute('domain') == 'tag']
nicenames = [c for c in categories if c.getAttribute('nicename') != '']
tags = [n.getAttribute('nicename') for n in nicenames]
comments = item.getElementsByTagNameNS('http://wordpress.org/export/1.0/','comment')
comments = len(comments)
content = item.getElementsByTagNameNS('http://purl.org/rss/1.0/modules/content/','encoded')[0]
content = '<item>' + content.firstChild.nodeValue + '</item>'
blurb = ''
try:
content = minidom.parseString(content)
paras = content.getElementsByTagName('p')
if len(paras) > 0:
blurb = content.getElementsByTagName('p')[0].toxml()
else:
_log('no paras found, using initial text')
content = content.getElementsByTagName('item')[0].toxml()
blurb = self._extractBlurb(content,self.blurb_max_len)
except:
_log('unparseable content:encoded, using initial text')
blurb = self._extractBlurb(content,self.blurb_max_len)
blurb = re.sub('<(.|\n)*?>', '', blurb)
blurb = re.sub('&', '&', blurb);
blurb = re.sub('"', '"', blurb);
_log('blurb: ' + blurb)
blurb = '<![CDATA[%s]]>' % blurb
pivot_item = PivotItem(i)
pivot_item.title = title
pivot_item.link = link
pivot_item.id = id
pivot_item.date = date
pivot_item.tags = tags
pivot_item.comments = str(comments)
pivot_item.blurb = blurb
self.images.append('%s.xml' % id)
self.pivot_items_xml += pivot_item.AsXml()
if self.do_images:
pivot_item.MakeJPEG()
pivot_item.MakeDZI()
i += 1
_log('-----------------------------')
except:
_log('error in ProcessItems at item %d ' % i)
_trace_log()
def MakeDZC(self):
creator = CollectionCreator()
_log('MakeDZC: %s, %s' % ( ','.join(self.images), self.dzc_output))
creator.create(self.images, self.dzc_output)
def AsXml(self):
cxml = self._cxml_template()
cxml = cxml.replace('__ITEMS__', self.pivot_items_xml)
return cxml
def _cxml_template(self):
return """<?xml version="1.0" encoding="utf-8"?>
<Collection xmlns:p="http://schemas.microsoft.com/livelabs/pivot/collection/2009" SchemaVersion="1.0" Name="jon's blog" xmlns="http://schemas.microsoft.com/collection/metadata/2009">
<FacetCategories>
<FacetCategory Name="date" Type="DateTime" Format="d" p:IsFilterVisible="true" p:IsWordWheelVisible="false" p:IsMetaDataVisible="true" />
<FacetCategory Name="tag" Type="String" p:IsFilterVisible="true" p:IsWordWheelVisible="true" p:IsMetaDataVisible="true" />
<!-- <FacetCategory Name="yearmonth" Type="String" p:IsFilterVisible="true" p:IsWordWheelVisible="true" p:IsMetaDataVisible="true" />-->
<FacetCategory Name="comments" Type="Number" p:IsFilterVisible="true" p:IsWordWheelVisible="false" p:IsMetaDataVisible="true" />
</FacetCategories>
<!-- <Items ImgBase="dzc_output.xml" HrefBase=""> -->
<Items ImgBase="dzc_output.xml">
__ITEMS__
</Items>
</Collection>"""
def main():
testing = False
do_images = True
pivot_items = PivotItemCollection(testing=testing,do_images=do_images)
pivot_items.items = pivot_items.items
pivot_items.ProcessItems()
f = codecs.open('pivot.cxml','w','utf-8')
f.write(pivot_items.AsXml())
f.close()
if do_images:
pivot_items.MakeDZC()
if __name__ == "__main__":
main()