You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pylucene-commits@lucene.apache.org by va...@apache.org on 2010/07/12 23:31:53 UTC

svn commit: r963493 - in /lucene/pylucene/branches/python_3/samples: IndexFiles.py PorterStemmerAnalyzer.py SearchFiles.py TermPositionVector.py ThreadIndexFiles.py manindex.py mansearch.py

Author: vajda
Date: Mon Jul 12 21:31:52 2010
New Revision: 963493

URL: http://svn.apache.org/viewvc?rev=963493&view=rev
Log:
2to3 on samples

Modified:
    lucene/pylucene/branches/python_3/samples/IndexFiles.py
    lucene/pylucene/branches/python_3/samples/PorterStemmerAnalyzer.py
    lucene/pylucene/branches/python_3/samples/SearchFiles.py
    lucene/pylucene/branches/python_3/samples/TermPositionVector.py
    lucene/pylucene/branches/python_3/samples/ThreadIndexFiles.py
    lucene/pylucene/branches/python_3/samples/manindex.py
    lucene/pylucene/branches/python_3/samples/mansearch.py

Modified: lucene/pylucene/branches/python_3/samples/IndexFiles.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/samples/IndexFiles.py?rev=963493&r1=963492&r2=963493&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/samples/IndexFiles.py (original)
+++ lucene/pylucene/branches/python_3/samples/IndexFiles.py Mon Jul 12 21:31:52 2010
@@ -36,23 +36,23 @@ class IndexFiles(object):
         writer.setMaxFieldLength(1048576)
         self.indexDocs(root, writer)
         ticker = Ticker()
-        print 'optimizing index',
+        print('optimizing index', end=' ')
         threading.Thread(target=ticker.run).start()
         writer.optimize()
         writer.close()
         ticker.tick = False
-        print 'done'
+        print('done')
 
     def indexDocs(self, root, writer):
         for root, dirnames, filenames in os.walk(root):
             for filename in filenames:
                 if not filename.endswith('.txt'):
                     continue
-                print "adding", filename
+                print("adding", filename)
                 try:
                     path = os.path.join(root, filename)
                     file = open(path)
-                    contents = unicode(file.read(), 'iso-8859-1')
+                    contents = str(file.read(), 'iso-8859-1')
                     file.close()
                     doc = lucene.Document()
                     doc.add(lucene.Field("name", filename,
@@ -66,21 +66,21 @@ class IndexFiles(object):
                                              lucene.Field.Store.NO,
                                              lucene.Field.Index.ANALYZED))
                     else:
-                        print "warning: no content in %s" % filename
+                        print("warning: no content in %s" % filename)
                     writer.addDocument(doc)
-                except Exception, e:
-                    print "Failed in indexDocs:", e
+                except Exception as e:
+                    print("Failed in indexDocs:", e)
 
 if __name__ == '__main__':
     if len(sys.argv) < 2:
-        print IndexFiles.__doc__
+        print(IndexFiles.__doc__)
         sys.exit(1)
     lucene.initVM()
-    print 'lucene', lucene.VERSION
+    print('lucene', lucene.VERSION)
     start = datetime.now()
     try:
         IndexFiles(sys.argv[1], "index", lucene.StandardAnalyzer(lucene.Version.LUCENE_CURRENT))
         end = datetime.now()
-        print end - start
-    except Exception, e:
-        print "Failed: ", e
+        print(end - start)
+    except Exception as e:
+        print("Failed: ", e)

Modified: lucene/pylucene/branches/python_3/samples/PorterStemmerAnalyzer.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/samples/PorterStemmerAnalyzer.py?rev=963493&r1=963492&r2=963493&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/samples/PorterStemmerAnalyzer.py (original)
+++ lucene/pylucene/branches/python_3/samples/PorterStemmerAnalyzer.py Mon Jul 12 21:31:52 2010
@@ -47,14 +47,14 @@ class PorterStemmerAnalyzer(PythonAnalyz
 
 if __name__ == '__main__':
     if len(sys.argv) < 2:
-        print IndexFiles.__doc__
+        print(IndexFiles.__doc__)
         sys.exit(1)
     initVM()
-    print 'lucene', VERSION
+    print('lucene', VERSION)
     start = datetime.now()
     try:
         IndexFiles(sys.argv[1], "index", PorterStemmerAnalyzer())
         end = datetime.now()
-        print end - start
-    except Exception, e:
-        print "Failed: ", e
+        print(end - start)
+    except Exception as e:
+        print("Failed: ", e)

Modified: lucene/pylucene/branches/python_3/samples/SearchFiles.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/samples/SearchFiles.py?rev=963493&r1=963492&r2=963493&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/samples/SearchFiles.py (original)
+++ lucene/pylucene/branches/python_3/samples/SearchFiles.py Mon Jul 12 21:31:52 2010
@@ -15,28 +15,28 @@ some cases.
 """
 def run(searcher, analyzer):
     while True:
-        print
-        print "Hit enter with no input to quit."
-        command = raw_input("Query:")
+        print()
+        print("Hit enter with no input to quit.")
+        command = input("Query:")
         if command == '':
             return
 
-        print
-        print "Searching for:", command
+        print()
+        print("Searching for:", command)
         query = QueryParser(Version.LUCENE_CURRENT, "contents",
                             analyzer).parse(command)
         scoreDocs = searcher.search(query, 50).scoreDocs
-        print "%s total matching documents." % len(scoreDocs)
+        print("%s total matching documents." % len(scoreDocs))
 
         for scoreDoc in scoreDocs:
             doc = searcher.doc(scoreDoc.doc)
-            print 'path:', doc.get("path"), 'name:', doc.get("name")
+            print('path:', doc.get("path"), 'name:', doc.get("name"))
 
 
 if __name__ == '__main__':
     STORE_DIR = "index"
     initVM()
-    print 'lucene', VERSION
+    print('lucene', VERSION)
     directory = SimpleFSDirectory(File(STORE_DIR))
     searcher = IndexSearcher(directory, True)
     analyzer = StandardAnalyzer(Version.LUCENE_CURRENT)

Modified: lucene/pylucene/branches/python_3/samples/TermPositionVector.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/samples/TermPositionVector.py?rev=963493&r1=963492&r2=963493&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/samples/TermPositionVector.py (original)
+++ lucene/pylucene/branches/python_3/samples/TermPositionVector.py Mon Jul 12 21:31:52 2010
@@ -22,16 +22,16 @@ iwriter.close()
 ireader = IndexReader.open(directory, True)
 tpv = TermPositionVector.cast_(ireader.getTermFreqVector(0, 'fieldname'))
 
-for (t,f,i) in zip(tpv.getTerms(),tpv.getTermFrequencies(),xrange(100000)):
-    print 'term %s' % t
-    print '  freq: %i' % f
+for (t,f,i) in zip(tpv.getTerms(),tpv.getTermFrequencies(),range(100000)):
+    print('term %s' % t)
+    print('  freq: %i' % f)
     try:
-        print '  pos: ' + str([p for p in tpv.getTermPositions(i)])
+        print('  pos: ' + str([p for p in tpv.getTermPositions(i)]))
     except:
-        print '  no pos'
+        print('  no pos')
     try:
-        print '  off: ' + \
+        print('  off: ' + \
               str(["%i-%i" % (o.getStartOffset(), o.getEndOffset())
-                   for o in tpv.getOffsets(i)])
+                   for o in tpv.getOffsets(i)]))
     except:
-        print '  no offsets'
+        print('  no offsets')

Modified: lucene/pylucene/branches/python_3/samples/ThreadIndexFiles.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/samples/ThreadIndexFiles.py?rev=963493&r1=963492&r2=963493&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/samples/ThreadIndexFiles.py (original)
+++ lucene/pylucene/branches/python_3/samples/ThreadIndexFiles.py Mon Jul 12 21:31:52 2010
@@ -23,10 +23,10 @@ from IndexFiles import IndexFiles
 
 if __name__ == '__main__':
     if len(sys.argv) < 2:
-        print IndexFiles.__doc__
+        print(IndexFiles.__doc__)
         sys.exit(1)
     env=initVM()
-    print 'lucene', VERSION
+    print('lucene', VERSION)
 
     def fn():
         env.attachCurrentThread()
@@ -34,6 +34,6 @@ if __name__ == '__main__':
         IndexFiles(sys.argv[1], "index",
                    StandardAnalyzer(Version.LUCENE_CURRENT))
         end = datetime.now()
-        print end - start
+        print(end - start)
 
     threading.Thread(target=fn).start()

Modified: lucene/pylucene/branches/python_3/samples/manindex.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/samples/manindex.py?rev=963493&r1=963492&r2=963493&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/samples/manindex.py (original)
+++ lucene/pylucene/branches/python_3/samples/manindex.py Mon Jul 12 21:31:52 2010
@@ -34,7 +34,7 @@ def indexDirectory(dir):
 def indexFile(dir,filename):
 
     path = os.path.join(dir, filename)
-    print "  File: ", filename
+    print("  File: ", filename)
 
     if filename.endswith('.gz'):
         child = Popen('gunzip -c ' + path + ' | groff -t -e -E -mandoc -Tascii | col -bx', shell=True, stdout=PIPE, cwd=os.path.dirname(dir)).stdout
@@ -47,7 +47,7 @@ def indexFile(dir,filename):
     data = child.read()
     err = child.close()
     if err:
-        raise RuntimeError, '%s failed with exit code %d' %(command, err)
+        raise RuntimeError('%s failed with exit code %d' %(command, err))
 
     matches = re.search('^NAME$(.*?)^\S', data,
                         re.MULTILINE | re.DOTALL)
@@ -81,7 +81,7 @@ def indexFile(dir,filename):
 if __name__ == '__main__':
 
     if len(sys.argv) != 2:
-        print "Usage: python manindex.py <index dir>"
+        print("Usage: python manindex.py <index dir>")
 
     else:
         initVM()
@@ -91,7 +91,7 @@ if __name__ == '__main__':
                              IndexWriter.MaxFieldLength.LIMITED)
         manpath = os.environ.get('MANPATH', '/usr/share/man').split(os.pathsep)
         for dir in manpath:
-            print "Crawling", dir
+            print("Crawling", dir)
             for name in os.listdir(dir):
                 path = os.path.join(dir, name)
                 if os.path.isdir(path):

Modified: lucene/pylucene/branches/python_3/samples/mansearch.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/samples/mansearch.py?rev=963493&r1=963492&r2=963493&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/samples/mansearch.py (original)
+++ lucene/pylucene/branches/python_3/samples/mansearch.py Mon Jul 12 21:31:52 2010
@@ -35,8 +35,8 @@ if __name__ == '__main__':
     initVM()
 
 def usage():
-    print sys.argv[0], "[--format=<format string>] [--index=<index dir>] [--stats] <query...>"
-    print "default index is found from MANDEX environment variable"
+    print(sys.argv[0], "[--format=<format string>] [--index=<index dir>] [--stats] <query...>")
+    print("default index is found from MANDEX environment variable")
 
 try:
     options, args = getopt(sys.argv[1:], '', ['format=', 'index=', 'stats'])
@@ -72,10 +72,10 @@ start = datetime.now()
 scoreDocs = searcher.search(query, 50).scoreDocs
 duration = datetime.now() - start
 if stats:
-    print >>sys.stderr, "Found %d document(s) (in %s) that matched query '%s':" %(len(scoreDocs), duration, query)
+    print("Found %d document(s) (in %s) that matched query '%s':" %(len(scoreDocs), duration, query), file=sys.stderr)
 
 for scoreDoc in scoreDocs:
     doc = searcher.doc(scoreDoc.doc)
     table = dict((field.name(), field.stringValue())
                  for field in doc.getFields())
-    print template.substitute(table)
+    print(template.substitute(table))