Back to index

moin  1.9.0~rc2
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
MoinMoin.support.xappy.fieldmappings.FieldMappings Class Reference
Collaboration diagram for MoinMoin.support.xappy.fieldmappings.FieldMappings:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def get_fieldname_from_prefix
def get_prefix
def get_slot
def add_prefix
def add_slot
def serialise

Private Member Functions

def _genPrefix

Private Attributes

 _prefixes
 _prefixcount
 _slots
 _slotcount

Static Private Attributes

string __slots__ = '_prefixes'

Detailed Description

Mappings from field names to term prefixes, slot values, etc.

The following mappings are maintained:

- a mapping from field name to the string prefix to insert at the start of
  terms.
- a mapping from field name to the slot numbers to store the field contents
  in.

Definition at line 25 of file fieldmappings.py.


Constructor & Destructor Documentation

def MoinMoin.support.xappy.fieldmappings.FieldMappings.__init__ (   self,
  serialised = None 
)
Create a new field mapping object, or unserialise a saved one.

Definition at line 38 of file fieldmappings.py.

00038 
00039     def __init__(self, serialised=None):
00040         """Create a new field mapping object, or unserialise a saved one.
00041 
00042         """
00043         if serialised is not None:
00044             (self._prefixes, self._prefixcount,
00045              self._slots, self._slotcount) = _cPickle.loads(serialised)
00046         else:
00047             self._prefixes = {}
00048             self._prefixcount = 0
00049             self._slots = {}
00050             self._slotcount = 0


Member Function Documentation

Generate a previously unused prefix.

Prefixes are uppercase letters, and start with 'X' (this is a Xapian
convention, for compatibility with other Xapian tools: other starting
letters are reserved for special meanings):

>>> maps = FieldMappings()
>>> maps._genPrefix()
'XA'
>>> maps._genPrefix()
'XB'
>>> [maps._genPrefix() for i in xrange(60)]
['XC', 'XD', 'XE', 'XF', 'XG', 'XH', 'XI', 'XJ', 'XK', 'XL', 'XM', 'XN', 'XO', 'XP', 'XQ', 'XR', 'XS', 'XT', 'XU', 'XV', 'XW', 'XX', 'XY', 'XZ', 'XAA', 'XBA', 'XCA', 'XDA', 'XEA', 'XFA', 'XGA', 'XHA', 'XIA', 'XJA', 'XKA', 'XLA', 'XMA', 'XNA', 'XOA', 'XPA', 'XQA', 'XRA', 'XSA', 'XTA', 'XUA', 'XVA', 'XWA', 'XXA', 'XYA', 'XZA', 'XAB', 'XBB', 'XCB', 'XDB', 'XEB', 'XFB', 'XGB', 'XHB', 'XIB', 'XJB']
>>> maps = FieldMappings()
>>> [maps._genPrefix() for i in xrange(27*26 + 5)][-10:]
['XVZ', 'XWZ', 'XXZ', 'XYZ', 'XZZ', 'XAAA', 'XBAA', 'XCAA', 'XDAA', 'XEAA']

Definition at line 51 of file fieldmappings.py.

00051 
00052     def _genPrefix(self):
00053         """Generate a previously unused prefix.
00054 
00055         Prefixes are uppercase letters, and start with 'X' (this is a Xapian
00056         convention, for compatibility with other Xapian tools: other starting
00057         letters are reserved for special meanings):
00058 
00059         >>> maps = FieldMappings()
00060         >>> maps._genPrefix()
00061         'XA'
00062         >>> maps._genPrefix()
00063         'XB'
00064         >>> [maps._genPrefix() for i in xrange(60)]
00065         ['XC', 'XD', 'XE', 'XF', 'XG', 'XH', 'XI', 'XJ', 'XK', 'XL', 'XM', 'XN', 'XO', 'XP', 'XQ', 'XR', 'XS', 'XT', 'XU', 'XV', 'XW', 'XX', 'XY', 'XZ', 'XAA', 'XBA', 'XCA', 'XDA', 'XEA', 'XFA', 'XGA', 'XHA', 'XIA', 'XJA', 'XKA', 'XLA', 'XMA', 'XNA', 'XOA', 'XPA', 'XQA', 'XRA', 'XSA', 'XTA', 'XUA', 'XVA', 'XWA', 'XXA', 'XYA', 'XZA', 'XAB', 'XBB', 'XCB', 'XDB', 'XEB', 'XFB', 'XGB', 'XHB', 'XIB', 'XJB']
00066         >>> maps = FieldMappings()
00067         >>> [maps._genPrefix() for i in xrange(27*26 + 5)][-10:]
00068         ['XVZ', 'XWZ', 'XXZ', 'XYZ', 'XZZ', 'XAAA', 'XBAA', 'XCAA', 'XDAA', 'XEAA']
00069         """
00070         res = []
00071         self._prefixcount += 1
00072         num = self._prefixcount
00073         while num != 0:
00074             ch = (num - 1) % 26
00075             res.append(chr(ch + ord('A')))
00076             num -= ch
00077             num = num // 26
00078         return 'X' + ''.join(res)

Here is the caller graph for this function:

Allocate a prefix for the given field.

If a prefix is already allocated for this field, this has no effect.

Definition at line 102 of file fieldmappings.py.

00102 
00103     def add_prefix(self, fieldname):
00104         """Allocate a prefix for the given field.
00105 
00106         If a prefix is already allocated for this field, this has no effect.
00107 
00108         """
00109         if fieldname in self._prefixes:
00110             return
00111         self._prefixes[fieldname] = self._genPrefix()

Here is the call graph for this function:

def MoinMoin.support.xappy.fieldmappings.FieldMappings.add_slot (   self,
  fieldname,
  purpose,
  slotnum = None 
)
Allocate a slot number for the given field and purpose.

If a slot number is already allocated for this field and purpose, this
has no effect.

Returns the slot number allocated for the field and purpose (whether
newly allocated, or previously allocated).

If `slotnum` is supplied, the number contained in it is used to
allocate the new slot, instead of allocating a new number.  No checks
will be made to ensure that the slot number doesn't collide with
existing (or later allocated) numbers: the main purpose of this
parameter is to share allocations - ie, to collide deliberately.

Definition at line 112 of file fieldmappings.py.

00112 
00113     def add_slot(self, fieldname, purpose, slotnum=None):
00114         """Allocate a slot number for the given field and purpose.
00115 
00116         If a slot number is already allocated for this field and purpose, this
00117         has no effect.
00118 
00119         Returns the slot number allocated for the field and purpose (whether
00120         newly allocated, or previously allocated).
00121 
00122         If `slotnum` is supplied, the number contained in it is used to
00123         allocate the new slot, instead of allocating a new number.  No checks
00124         will be made to ensure that the slot number doesn't collide with
00125         existing (or later allocated) numbers: the main purpose of this
00126         parameter is to share allocations - ie, to collide deliberately.
00127 
00128         """
00129         try:
00130             return self._slots[(fieldname, purpose)]
00131         except KeyError:
00132             pass
00133 
00134         if slotnum is None:
00135             self._slots[(fieldname, purpose)] = self._slotcount
00136             self._slotcount += 1
00137             return self._slotcount - 1
00138         else:
00139             self._slots[(fieldname, purpose)] = slotnum
00140             return slotnum

Get a fieldname from a prefix.

If the prefix is not found, return None.

Definition at line 79 of file fieldmappings.py.

00079 
00080     def get_fieldname_from_prefix(self, prefix):
00081         """Get a fieldname from a prefix.
00082 
00083         If the prefix is not found, return None.
00084 
00085         """
00086         for key, val in self._prefixes.iteritems():
00087             if val == prefix:
00088                 return key
00089         return None

Get the prefix used for a given field name.

Definition at line 90 of file fieldmappings.py.

00090 
00091     def get_prefix(self, fieldname):
00092         """Get the prefix used for a given field name.
00093 
00094         """
00095         return self._prefixes[fieldname]

def MoinMoin.support.xappy.fieldmappings.FieldMappings.get_slot (   self,
  fieldname,
  purpose 
)
Get the slot number used for a given field name and purpose.

Definition at line 96 of file fieldmappings.py.

00096 
00097     def get_slot(self, fieldname, purpose):
00098         """Get the slot number used for a given field name and purpose.
00099 
00100         """
00101         return self._slots[(fieldname, purpose)]

Serialise the field mappings to a string.

This can be unserialised by passing the result of this method to the
constructor of a new FieldMappings object.

Definition at line 141 of file fieldmappings.py.

00141 
00142     def serialise(self):
00143         """Serialise the field mappings to a string.
00144 
00145         This can be unserialised by passing the result of this method to the
00146         constructor of a new FieldMappings object.
00147 
00148         """
00149         return _cPickle.dumps((self._prefixes,
00150                                self._prefixcount,
00151                                self._slots,
00152                                self._slotcount,
00153                               ), 2)

Member Data Documentation

Definition at line 36 of file fieldmappings.py.

Definition at line 47 of file fieldmappings.py.

Definition at line 46 of file fieldmappings.py.

Definition at line 49 of file fieldmappings.py.

Definition at line 48 of file fieldmappings.py.


The documentation for this class was generated from the following file: