def test_lattice_add(): l1 = lattice.Lattice([[0, 10, 6]]) l2 = lattice.Lattice([[0, 5, 3]]) l_add = l1 + l2 assert l1.dim == 1 assert l2.dim == 1 assert l_add.dim == 2
def test_field_lattice_set(): z_counter = [0] # cheat to see in which order field vaules are set def mydata(pos): print("type of pos = {}".format(type(pos))) print("pos = {}".format(pos)) # use position as field data (for our testing here) x, y = pos z = z_counter[0] z_counter[0] += 0.1 return [x, y, z] fl = lattice.FieldLattice(lattice.Lattice([[0, 5, 6], [-2, -1, 2]])) fl.set(mydata) print(fl.field_data.shape) print(fl.field_data[:, :, :]) print("==============") print(fl.field_data[2, :, :]) print(np.array([np.linspace(0, 1.1, 12)])) print("==============") # check x-component assert np.allclose( fl.field_data[0, :, :], np.array([[0., 0.], [1., 1.], [2., 2.], [3., 3.], [4., 4.], [5., 5.]])) # check y-component assert np.allclose( fl.field_data[1, :, :], np.array([[-2., -1.], [-2., -1.], [-2., -1.], [-2., -1.], [-2., -1.], [-2., -1.]])) # check z-component in Fortran ordering assert np.allclose( fl.field_data[2, :, :], np.array([[0.0, 0.6], [0.1, 0.7], [0.2, 0.8], [0.3, 0.9], [0.4, 1.0], [0.5, 1.1]])) # How does C order differ? # Okay, simplify: establish only that C-order is different from F-order: flf = fl # FieldLattice Fortran # Create FieldLattice C with identical data flc = lattice.FieldLattice(lattice.Lattice([[0, 5, 6], [-2, -1, 2]]), order="C") z_counter[0] = 0 fl.set(mydata) print("Fortran field_data: {}".format(flf.field_data)) print("C field_data: {}".format(flc.field_data)) # compare values (should be the same) # Hans: 2015: this passes on OS X (and travis?) but not on Osiris (Ubuntu 64) assert np.allclose(flc.field_data, flf.field_data) # check that the strides are different (check help(numpy.ndarray)) assert flc.field_data.strides != flf.field_data.strides
def test_lattice_object(): # can call with spec as in min, max, num: l1 = lattice.Lattice([[0., 10., 6]]) # or with string l2 = lattice.Lattice("0.,10.,6") # should result in the same object assert np.allclose(l1.get_positions(), l2.get_positions()) # only order 'C' and 'F' allowed l2 = lattice.Lattice("0.,10.,6", order='F') l2 = lattice.Lattice("0.,10.,6", order='C') with pytest.raises(ValueError): l2 = lattice.Lattice("0.,10.,6", order='B')
def make_lattice(self): #Generate sites (with positions, but no neighbours) lat = lattice.Lattice() for zig in range(0, self.n_zig): if zig % 2 == 0: for l in range(self.n_uc * 2): xpos = l // 2 * np.sqrt(3) + np.sqrt(3) / 2 * (l % 2) ypos = zig * 3 / 2 + 1 / 2 * (l % 2) idx1 = zig * self.n_uc * 2 + l lat.sites.append( lattice.Site( idx1, np.array( [xpos * self.spacing, ypos * self.spacing]))) else: for l in range(self.n_uc * 2): xpos = l // 2 * np.sqrt(3) + np.sqrt(3) / 2 * ((l + 1) % 2) ypos = zig * 3 / 2 + 1 / 2 * (l % 2) idx1 = zig * self.n_uc * 2 + l lat.sites.append( lattice.Site( idx1, np.array( [xpos * self.spacing, ypos * self.spacing]))) #Fill in neighbours for each site with periodic boundary conditions and set hopping to 1 for site in lat.sites: neigh = self.get_neighbours(site.idx) site.neighbours = neigh site.hopping = [1] * len(neigh) return lat
def make_agnr(self): #returns an AGNR lattice with periodic boundary conditions and all hopping strengths set to 1 #and with indices ordered by starting in the bottom left and then going along the dimer lines #to the right. When the boundary start go to the left of the above dimer line. #geometry of lattice to determine the position of the sites unit_vectors = self.unit_vectors() shift0, shift1, shift2 = self.neighbour_vectors() distance_dim = np.abs(shift2[1]) lat = lattice.Lattice() #Generate sites (with positions) for dim in range(0, self.dimer): xpos = (dim % 2) * ( -shift1[0] ) #odd dimer lines start indented by 0.5*spacing, even start at 0 for l in range(0, self.length): idx = dim * self.length + l ypos = distance_dim * dim lat.sites.append(lattice.Site(idx, np.array([xpos, ypos]))) if (l + dim % 2) % 2 == 0: xpos += (-shift1[0] + unit_vectors[1][0]) else: xpos += self.spacing #Fill in neighbours for each site with periodic boundary conditions and set hopping to 1 for site in lat.sites: neigh = self._get_neighbours(site.idx) site.neighbours = neigh site.hopping = [1] * len(neigh) return lat
def test1(): # import lattice import os # latticepath = os.path.join(os.getcwd(), '../lattice') ltefile = os.path.join(latticepath, 'linac.lte') latticepath = '/home/tong/Programming/projects/vFEL/simulation/SXFEL' ltefile = os.path.join(latticepath, 'sxfel_v14b.lte') lpins = lattice.LteParser(ltefile) allelements_str = lpins.file2json() # print(allelements_str) latins = lattice.Lattice(allelements_str) outlatfile = os.path.join(latticepath, 'tmp.lte') # latins.showBeamlines() # print(latins.getFullBeamline('M1BI3', extend = True)) # print(latins.getAllBl()) # print(latins.getAllEle()) # print(latins.getBeamline('l0')) # print(latins.getFullBeamline('nl2', extend = True)) # print(lpins.getKwAsDict('Q01')) # print(lpins.getKwAsJson('BC1')) # print(lpins.getKwAsJson('testline')) # for e in latins.getFullBeamline('bl', extend = True): # print(latins.getElementType(e)) print(latins.getElementConf('c', raw=True)) print(latins.getElementProperties('c')) """
def runparams(param, n_equil=500000, n_calc=250000): L = lattice.Lattice(n=param[0], T=param[3], state=param[1], J=param[2]) print("Run:%s Equilibrating..." % L.config) sys.stdout.flush() for i in xrange(n_equil): L.cstep() print("Done!") sys.stdout.flush() Etotals = [] Stotals = [] Etotal = L.H() Stotal = L.spintotal() Etotals.append(Etotal) Stotals.append(Stotal) print("Run:%s Calculating..." % L.config) sys.stdout.flush() for i in xrange(n_calc): Ediff, Sdiff = L.cstep() Etotal += Ediff Stotal += Sdiff Etotals.append(Etotal) Stotals.append(Stotal) print("Done!") sys.stdout.flush() fileio.writedata("results/%s.txt" % L.config, [Etotals, Stotals])
def roll_tube(self, ribbon): """ Roll a 2D ribbon into a 3D nanotube. Rolls along the chiral vector Ch. The translation vector T becomes the direction of the tube. """ Ch = self.chiral_vector() ch = np.linalg.norm(Ch) uCh = Ch / ch T = self.translation_vector() t = np.linalg.norm(T) uT = T / t radius = self.diameter()/2 # turns 2D ribbon coordinate in Ch-direction into an angle angle_conversion = 2*np.pi/np.linalg.norm(self.chiral_vector()) tube = lattice.Lattice(name="Tube ({}, {})".format(*self.chirality)) for site in ribbon: # zylinder coordinates phi = angle_conversion*np.dot(site.pos, uCh) z = np.dot(site.pos, uT) tube.sites.append(lattice.Site(site.idx, np.array((radius*np.cos(phi), radius*np.sin(phi), z)), site.neighbours, site.hopping)) return tube
def get_replicas(self, residues): replicas = [] for i in range(self.num_replicas): coors_list = [(j, 0, 0) for j in range(len(residues))] lat = lattice.Lattice(residues, coors_list, i) replicas.append(lat) return replicas
def visualize_simple_walk(): l = lattice.Lattice(length=10, num_total_individuals=1, num_infected=1, beta=0.5, diffusion_rate=0.5, gamma=0) l.run_simulation(plot=True, optimize=False, plotstep=1)
def detailed_plot_of_single_run(length=100, ind=1000, infected=10): l = lattice.Lattice(length=length, num_total_individuals=ind, num_infected=infected, beta=0.5, diffusion_rate=0.5, gamma=0.017) l.run_simulation(plot=True, optimize=False)
def __getitem__(self, idx): return (lattice.Lattice(self.data[idx], self.word_mean, self.word_std, self.subword_mean, self.subword_std, lattice_type=self.lattice_type), lattice.Target(self.target[idx]))
def new_from_csv(cls, index, filename): print "Trimming coils", index, filename settings = run_sim.get_run_settings_from_csv(index, filename) settings["MatchCoil1_DS"] = 0. if settings == None: print "Failed to load csv filename", filename, "index", index return None a_lattice = lattice.Lattice(settings["momentum"], 0.) a_lattice.set_magnet_scale_factors(settings) z_range = range(-3000, -1800, 20) return TrimCoils(a_lattice, z_range)
def plaintext_to_lattice(self, infile): for fline in infile: edges = [lattice.Edge(span=(0, 1), label='<foreign-sentence>')] vid = 1 for fw in fline.split(): edges.append( lattice.Edge(span=(vid, vid + 1), label=fw, properties={'tok': '10^-1'})) vid += 1 yield lattice.Lattice(lines=edges) # TODO: sentence id?
def test_lattice_object_2d_scale(): l = lattice.Lattice([[0, 10, 6], [-3, 1, 2]]) assert l.dim == 2 l.scale(2) assert l.max_node_pos == [20, 2] assert l.stepsizes == [4, 8] l.scale(0.5) assert l.max_node_pos == [10, 1] assert l.stepsizes == [2, 4]
def test_lattice_object_2d(): l = lattice.Lattice([[0, 10, 6], [-3, 1, 2]]) assert l.dim == 2 check_points_index = [] check_points_value = [] def f(idx, x): print("idx = {} x={}".format(idx, x)) check_points_index.append(idx[:]) check_points_value.append(x[:]) l.foreach(f) assert check_points_index == [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1]] assert np.allclose(check_points_value, [[0.0, -3.0], [2.0, -3.0], [4.0, -3.0], [6.0, -3.0], [8.0, -3.0], [10.0, -3.0], [0.0, 1.0], [2.0, 1.0], [4.0, 1.0], [6.0, 1.0], [8.0, 1.0], [10.0, 1.0]]) assert l.get_closest([1.01, -0.9]) == [1, 1] assert l.get_closest([1.01, -1.0001]) == [1, 0] assert l.get_num_points() == 12 assert l.dim == 2 with pytest.raises(IndexError): l.get_pos_from_idx([1]) # should raise IndexError for 2d mesh l.get_pos_from_idx([0, 0]) == [0., -3.] l.get_pos_from_idx([0, 1]) == [0., 1.] l.get_pos_from_idx([4, 1]) == [8., 1.] assert l.get_shape() == [6, 2] l.max_node_pos == [10, 1] assert l.min_max_num_list == [[0, 10, 6], [-3, 1, 2]] assert l.min_node_pos == [0, -3] assert l.nodes == [6, 2] assert l.order == 'F' assert str(l) == "Lattice([[0, 10, 6], [-3, 1, 2]])" assert np.allclose( l.get_positions(), np.array([[[0., -3.], [2., -3.], [4., -3.], [6., -3.], [8., -3.], [10., -3.]], [[0., 1.], [2., 1.], [4., 1.], [6., 1.], [8., 1.], [10., 1.]]]))
def make_step(self, lat, T, rot_gen): """Performs a Metropolis step on the lattice lat.""" new_coors_list = self.random_transform_coors(lat, rot_gen) if new_coors_list is not None: new_lat = lattice.Lattice(lat.residues, new_coors_list) curr_energy = lat.get_energy() new_energy = new_lat.get_energy() if new_energy <= curr_energy: lat.set_coors_list(new_coors_list) else: r = np.exp(-(new_energy - curr_energy) / T) if random.uniform(0, 1) < r: lat.set_coors_list(new_coors_list)
def test_field_lattice_init(): fl = lattice.FieldLattice(lattice.Lattice([[0, 10, 6], [-3, 1, 2]])) # we want to see numpy.ndarray for the data assert type(fl.field_data) == np.ndarray # and contiguous data assert fl.field_data.flags['F_CONTIGUOUS'] is True # and the right shape assert fl.field_data.shape[1:] == tuple(fl.lattice.get_shape()) # and 3d data vectors assert fl.field_data.shape[0] == 3 == fl.field_dim # but the lattice is in 2d only assert fl.lattice.dim == 2
def _test_lattice(): data = { "a": [1, 2, 3, 4, 5, 6, 7], "b": [5, 5, 5, 5, 5, 5, 5], "c": [9, 5, 7, 1, 1, 9, 5], "d": [5, 5, 5, 5, 2, 5, 5], "e": [0, 0, 8, 9, 5, 5, 9], "f": [8, 3, 9, 5, 1, 1, 0], "g": [5, 5, 2, 9, 0, 0, 9] } ctx = pd.DataFrame(data) lattice = l.Lattice(ctx, 4) concept_a = lattice.find_concept_for_object("a") concept_f = lattice.find_concept_for_object("f") print("\nA") print(concept_a) print("\nF") print(concept_f)
def _run_simulation(beta, r_0, diff_rate, iterations=5): gamma = np.float64(beta) / r_0 print("running with beta: %s, r_0: %s, gamma: %s" % (beta, r_0, gamma)) l = lattice.Lattice(length=100, num_total_individuals=1000, num_infected=10, beta=beta, diffusion_rate=diff_rate, gamma=gamma) r_inf = 0 for i in range(iterations): print(" iteration %s..." % i) l.reset() tmp_r_inf = l.run_simulation(plot=False) print(" %s" % tmp_r_inf) r_inf += tmp_r_inf avg_r_inf = r_inf / iterations print(" average: %s" % avg_r_inf) return avg_r_inf
def test_penn_setup_b0(self): """Test the B0 button""" sys.argv += ["--configuration_file", TEST_DIR + "test_config_2.py"] self.main_window.lattice = lattice.Lattice() # resets fields I hope self.beam_setup.window.get_frame("&Penn", "button").Clicked() penn = self.beam_setup.matrix_select # Check Get BO self.hit_full['x'] = 100. self.hit_full['y'] = 100. self.hit_full['z'] = 100. self.beam_setup.set_reference(self.hit_full) penn.window.get_frame("Get &B0", "button").Clicked() b_vec = maus_cpp.field.get_field_value(100., 100., 100., 0.) b_mag = 0. for i in range(3): b_mag += b_vec[i]**2 self.assertGreater(1.e3 * b_mag**0.5, 1e-2) # check bfield is non-zero self.assertAlmostEqual(penn.window.get_text_entry("B0", type(1.)), 1.e3 * b_mag**0.5, 3) # check field is correct
def test(): # pvs = ('sxfel:lattice:Q01', 'sxfel:lattice:Q02') # A = Models(*pvs) latline = Models(name='BL') ch = element.ElementCharge(name='q', config="total = 1e-9") d1 = element.ElementDrift(name='d1', config="l = 1.0") q1 = element.ElementQuad(name='Q1', config="l = 1.0, k1 = 10") lat1 = [d1, q1, q1] * 10 latline.addElement(ch, lat1) latdict = latline.LatticeDict # generate lattice import lattice import json latins = lattice.Lattice(json.dumps(latdict)) # print(latins.getAllEle()) # print(latins.getAllBl()) latfile = "/home/tong/Programming/projects/beamline/tests/test_models/fortest.lte" latins.generateLatticeFile(latline.name, latfile)
def make_ribbon(self, n_ucells, bc_ch, bc_t): """ Create a 2D nano ribbon with given number of unit cells and boundary conditions. """ T = self.translation_vector() # make a unit cell ucell = self._make_ucell() # replicate unit cell along T ribbon = lattice.Lattice(name="Ribbon ({}, {})".format(*self.chirality)) for i in range(n_ucells): shifted = lattice.shifted_lattice(ucell, i*T) for site in shifted: site.idx += i*len(ucell) ribbon.sites.extend(shifted) # combine cells and handle boundary conditions _sow_cells(ribbon.sites, n_ucells, len(ucell), bc_ch, bc_t) return ribbon
def test_gb_2d_csl(): """ Test the two-dimensional boundary plane basis in bp_basis function """ Mat = np.zeros(6, dtype=[('t_g1tog2_go1', '(3,3)float64'), ('bp1_go1', '(3,1)float64')]) Mat['bp1_go1'][0] = np.array([[0.5], [0.], [-0.5]]) Mat['bp1_go1'][1] = np.array([[1.5], [-0.5], [-1.0]]) Mat['bp1_go1'][2] = np.array([[11.], [-4.0], [-4.0]]) Mat['bp1_go1'][3] = np.array([[12.5], [0.5], [-1.0]]) Mat['bp1_go1'][4] = np.array([[3.5], [2.0], [0.5]]) Mat['bp1_go1'][5] = np.array([[3.], [-0.5], [-0.5]]) Mat['t_g1tog2_go1'][0] = np.array([[2. / 3, -1. / 3, 2. / 3], [2. / 3, 2. / 3, -1. / 3], [-1. / 3, 2. / 3, 2. / 3]]) Mat['t_g1tog2_go1'][1] = np.array([[2. / 3, -1. / 3, 2. / 3], [2. / 3, 2. / 3, -1. / 3], [-1. / 3, 2. / 3, 2. / 3]]) Mat['t_g1tog2_go1'][2] = np.array([[1. / 3, 2. / 3, 2. / 3], [-2. / 3, 2. / 3, -1. / 3], [-2. / 3, -1. / 3, 2. / 3]]) Mat['t_g1tog2_go1'][3] = np.array([[-2. / 3, -1. / 3, 2. / 3], [1. / 3, 2. / 3, 2. / 3], [-2. / 3, 2. / 3, -1. / 3]]) Mat['t_g1tog2_go1'][4] = np.array([[-2. / 3, -2. / 3, 1. / 3], [-2. / 3, 1. / 3, -2. / 3], [1. / 3, -2. / 3, -2. / 3]]) Mat['t_g1tog2_go1'][5] = np.array([[1. / 3, 2. / 3, 2. / 3], [-2. / 3, 2. / 3, -1. / 3], [-2. / 3, -1. / 3, 2. / 3]]) for i in range(Mat.shape[0]): AL = lat.Lattice('Al') bp1_go1 = Mat['bp1_go1'][i] t_g1tog2_go1 = Mat['t_g1tog2_go1'][i] a, b, c = bpb.bicryst_planar_den(bp1_go1, t_g1tog2_go1, AL) print('Pl Density 1=', a, '\nPl Density 2=', b, '\nPl Density_2D CSL=', c) print '\n------------\n'
def _make_ucell(self): """ Create a single unit cell for a tube. All nearest neighbours in the cell are connected with periodic boundary conditions. Sites are placed at integer multiples of the symmetry vector R. i*R is projected onto Ch and T and the modulo is taken to make sure it stays within the unit cell. See psi and tau below. """ Ch = self.chiral_vector() ch = np.linalg.norm(Ch) uCh = Ch / ch T = self.translation_vector() t = np.linalg.norm(T) uT = T / t R = self.symmetry_vector() a1, a2 = self.unit_vectors() eo_shift = 1/3 * (a1 + a2) # vector to get from an even site to one of its odd neighbours ucell = lattice.Lattice() idx = 0 for i in range(self.n_atoms_ucell()//2): # even psi = np.dot(i*R, uCh) % ch tau = np.dot(i*R, uT) % t ucell.sites.append(lattice.Site(idx, psi*uCh + tau*uT, even=True)) idx += 1 # odd psi = np.dot(i*R + eo_shift, uCh) % ch tau = np.dot(i*R + eo_shift, uT) % t ucell.sites.append(lattice.Site(idx, psi*uCh + tau*uT, even=False)) idx += 1 self._connect_sites(ucell) return ucell
def test_lattice_object_1d_scales(): l = lattice.Lattice([[0, 10, 6]]) assert l.dim == 1 l.scale(0.5) assert l.max_node_pos == [5] assert l.stepsizes == [1] l.scale(1 / 0.5) assert l.max_node_pos == [10] assert l.stepsizes == [2] # scale differently in different directions (silly for 1d) l.scale([0.5]) assert l.max_node_pos == [5] assert l.stepsizes == [1] l.scale(1 / 0.5) assert l.max_node_pos == [10] assert l.stepsizes == [2]
def _padded_lattice(self, lat): """ Pad a given lattice by surrounding it with copies of the input. The input must be a 2D lattice. All site attributes are preserved in the copies. Only the positions are updated additional attributes called 'pad_ch' and 'pad_t' are added to all sites. For the centre lattice, they are each 0. For the surrounding lattices, they are 0 or +-1 depending on whether the lattice is translated in Ch or T direction with respect to the centre. """ Ch = self.chiral_vector() T = self.translation_vector() padded = lattice.Lattice() for pad_ch, pad_t in itertools.product((0, +1, -1), repeat=2): aux = lattice.shifted_lattice(lat, pad_ch*Ch + pad_t*T) aux["pad_ch"] = pad_ch aux["pad_t"] = pad_t padded.sites.extend(aux) return padded
def test_lattice_object_1d(): l = lattice.Lattice([[0, 10, 6]]) assert l.dim == 1 check_points_index = [] check_points_value = [] def f(idx, x): print("idx = {} x={}".format(idx, x)) check_points_index.append(idx[0]) check_points_value.append(x[0]) l.foreach(f) assert check_points_index == list(range(6)) assert np.allclose(check_points_value, np.linspace(0, 10, 6)) assert l.get_closest([1.01]) == [1] assert l.get_closest([0.99]) == [0] assert l.get_num_points() == 6 assert l.get_pos_from_idx([4]) == [8] assert l.get_shape() == [6] assert l.max_node_pos == [10] assert l.min_node_pos == [0] assert l.min_max_num_list == [[0, 10, 6]] assert l.order == 'F' assert l.nodes == [6] assert str(l) == "Lattice([[0, 10, 6]])" assert l.stepsizes == [2] assert np.allclose(l.get_positions()[:, 0], np.linspace(0, 10, 6))
def __add__(self, other): if not isinstance(other, Pattern2d): raise ValueError('Only \'Pattern2d\' can be added!') if not hasattr(other, 'peaks'): raise ValueError('No peaks information!') if not self.xray == other.xray: raise ValueError('XRAY should be identical!') new = self.copy() new.sx = np.hstack((self.sx, other.sx)) new.num_tag(self.sx) new.peaks = np.hstack((self.peaks, other.peaks)) return new if __name__ == '__main__': lttc = LTTC.Lattice(material='Si') sx = SX.SingleXtal(lttc, x=(1, 0, 0), z=(0, 0, 1)) # sx.rotate_by(axis = (1,0,0), degree = -6) # xr = XR.Xray(wavelength = np.linspace(0.5, 0.6, 1000)) xr = XR.Xray('White') inc = Vector(0, 0, 1) p = Pattern2d(sx=sx, xray=xr, inc=inc) p.Calc(hklrange=(5, 5, 10)) p.show() p.save('peaks.txt')
def split_and_print(self, latticeIter): for lat in latticeIter: #print "DEBUG: " + str(lat) self.linesExamined += 1 if self.linesExamined % 100 == 0: sys.stderr.write("%d sentences, %d skipped, %s per second\n" % (self.linesExamined, self.linesSkipped, float(self.linesExamined) / monitor.cpu())) edges = [] initial_start = 0 next_fake_id = -1 # when splitting words, we add fake id (which are negative) -- to be fixed later for fed in sorted(lat.lines, lambda x, y: cmp(x.span, y.span)): # only supports simple lattices right now # TODO: change to support blocks? # add basic edge to edges list (ids will change later) edges.append(fed) sent_initial = fed.span[0] == initial_start if fed.span == (0, 1) and fed.label == '<foreign-sentence>': # foreign sentence is handled specially initial_start = 1 continue fw = fed.label remaining_fw = fw remaining_fw_start_pos, remaining_fw_end_pos = fed.span if opts.add_identity_arcs and make_identity(fw): edges.append( lattice.Edge(span=(remaining_fw_start_pos, remaining_fw_end_pos), label=fw, properties={ 'identity': '10^-1', 'target': 'NNP("' + fw + '")' })) if self.morphTable: used = set([]) # to avoid double use of affixes for m in self.morphTable.iter(): fanalysis = m.analyze_arabic(remaining_fw, sent_initial, used) if fanalysis: if fanalysis.prefixes and len( fanalysis.prefixes) > 0: sent_initial = False # only keep the sentence initial flag if there are no prefixes...? for pr in fanalysis.prefixes: edges.append( lattice.Edge( span=(remaining_fw_start_pos, next_fake_id), label=pr, properties={'s_morph': '10^-1'})) remaining_fw_start_pos = next_fake_id next_fake_id -= 1 # fake id's "increase" in negative space if fanalysis.suffixes and len( fanalysis.suffixes) > 0: fanalysis.suffixes.reverse( ) # we want to walk backward over this list for sf in fanalysis.suffixes: edges.append( lattice.Edge( span=(next_fake_id, remaining_fw_end_pos), label=sf, properties={'s_morph': '10^-1'})) remaining_fw_end_pos = next_fake_id next_fake_id -= 1 # fake id's "increase" in negative space # place the baseword itself there if fanalysis.baseword: edges.append( lattice.Edge( span=(remaining_fw_start_pos, remaining_fw_end_pos), label=fanalysis.baseword, properties={'s_morph': '10^-1'})) remaining_fw = fanalysis.baseword else: sys.stderr.write( "Analysis of word '%s' missing baseword using morph transform %s" % (remaining_fw, str(m))) self.f_outfile.write( str( lattice.Lattice(lines=fix_edges(edges), properties=lat.properties)) + ";\n") #except Error, inst: # print "Error encountered splitting affixes:", inst # self.linesSkipped += 1 # if self.f_outfile: # self.f_outfile.write(????) # continue sys.stderr.write("%d sentences, %d skipped, %s per second\n" % (self.linesExamined, self.linesSkipped, float(self.linesExamined) / monitor.cpu()))