_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
75
19.8k
language
stringclasses
1 value
meta_information
dict
q23400
polygon_hash
train
def polygon_hash(polygon): """ Return a vector containing values representitive of a particular polygon. Parameters --------- polygon : shapely.geometry.Polygon Input geometry Returns --------- hashed: (6), float Representitive values representing input polygon """ ...
python
{ "resource": "" }
q23401
random_polygon
train
def random_polygon(segments=8, radius=1.0): """ Generate a random polygon with a maximum number of sides and approximate radius. Parameters --------- segments: int, the maximum number of sides the random polygon will have radius: float, the approximate radius of the polygon desired Retur...
python
{ "resource": "" }
q23402
polygon_scale
train
def polygon_scale(polygon): """ For a Polygon object, return the diagonal length of the AABB. Parameters ------------ polygon: shapely.geometry.Polygon object Returns ------------ scale: float, length of AABB diagonal """ extents = np.reshape(polygon.bounds, (2, 2)).ptp(axis=0)...
python
{ "resource": "" }
q23403
paths_to_polygons
train
def paths_to_polygons(paths, scale=None): """ Given a sequence of connected points turn them into valid shapely Polygon objects. Parameters ----------- paths : (n,) sequence Of (m,2) float, closed paths scale: float Approximate scale of drawing for precision Returns ...
python
{ "resource": "" }
q23404
repair_invalid
train
def repair_invalid(polygon, scale=None, rtol=.5): """ Given a shapely.geometry.Polygon, attempt to return a valid version of the polygon through buffering tricks. Parameters ----------- polygon: shapely.geometry.Polygon object rtol: float, how close does a perimeter have to be scale:...
python
{ "resource": "" }
q23405
export_gltf
train
def export_gltf(scene, extras=None, include_normals=False): """ Export a scene object as a GLTF directory. This puts each mesh into a separate file (i.e. a `buffer`) as opposed to one larger file. Parameters ----------- scene : trimesh.Scene Scene to b...
python
{ "resource": "" }
q23406
load_gltf
train
def load_gltf(file_obj=None, resolver=None, **mesh_kwargs): """ Load a GLTF file, which consists of a directory structure with multiple files. Parameters ------------- file_obj : None or file-like Object containing header JSON, or None resolver : trimesh.vi...
python
{ "resource": "" }
q23407
load_glb
train
def load_glb(file_obj, resolver=None, **mesh_kwargs): """ Load a GLTF file in the binary GLB format into a trimesh.Scene. Implemented from specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0 Parameters ------------ file_obj : file- like object Containing...
python
{ "resource": "" }
q23408
_mesh_to_material
train
def _mesh_to_material(mesh, metallic=0.0, rough=0.0): """ Create a simple GLTF material for a mesh using the most commonly occurring color in that mesh. Parameters ------------ mesh: trimesh.Trimesh Mesh to create a material from Returns ------------ material: dict In G...
python
{ "resource": "" }
q23409
_create_gltf_structure
train
def _create_gltf_structure(scene, extras=None, include_normals=False): """ Generate a GLTF header. Parameters ------------- scene : trimesh.Scene Input scene data extras : JSON serializable Will be stored in the extras field ...
python
{ "resource": "" }
q23410
_byte_pad
train
def _byte_pad(data, bound=4): """ GLTF wants chunks aligned with 4- byte boundaries so this function will add padding to the end of a chunk of bytes so that it aligns with a specified boundary size Parameters -------------- data : bytes Data to be padded bound : int Leng...
python
{ "resource": "" }
q23411
_append_path
train
def _append_path(path, name, tree, buffer_items): """ Append a 2D or 3D path to the scene structure and put the data into buffer_items. Parameters ------------- path : trimesh.Path2D or trimesh.Path3D Source geometry name : str Name of geometry tree : dict Will be upda...
python
{ "resource": "" }
q23412
_parse_materials
train
def _parse_materials(header, views): """ Convert materials and images stored in a GLTF header and buffer views to PBRMaterial objects. Parameters ------------ header : dict Contains layout of file views : (n,) bytes Raw data Returns ------------ materials : list ...
python
{ "resource": "" }
q23413
_convert_camera
train
def _convert_camera(camera): """ Convert a trimesh camera to a GLTF camera. Parameters ------------ camera : trimesh.scene.cameras.Camera Trimesh camera object Returns ------------- gltf_camera : dict Camera represented as a GLTF dict """ result = { "name": ...
python
{ "resource": "" }
q23414
FilePathResolver.get
train
def get(self, name): """ Get an asset. Parameters ------------- name : str Name of the asset Returns ------------ data : bytes Loaded data from asset """ # load the file by path name with open(os.path.join(self...
python
{ "resource": "" }
q23415
ZipResolver.get
train
def get(self, name): """ Get an asset from the ZIP archive. Parameters ------------- name : str Name of the asset Returns ------------- data : bytes Loaded data from asset """ # not much we can do with that if ...
python
{ "resource": "" }
q23416
WebResolver.get
train
def get(self, name): """ Get a resource from the remote site. Parameters ------------- name : str Asset name, i.e. 'quadknot.obj.mtl' """ # do import here to keep soft dependency import requests # append base url to requested name ...
python
{ "resource": "" }
q23417
Geometry.apply_translation
train
def apply_translation(self, translation): """ Translate the current mesh. Parameters ---------- translation : (3,) float Translation in XYZ """ translation = np.asanyarray(translation, dtype=np.float64) if translation.shape != (3,): ...
python
{ "resource": "" }
q23418
Geometry.apply_scale
train
def apply_scale(self, scaling): """ Scale the mesh equally on all axis. Parameters ---------- scaling : float Scale factor to apply to the mesh """ scaling = float(scaling) if not np.isfinite(scaling): raise ValueError('Scaling facto...
python
{ "resource": "" }
q23419
Geometry.bounding_box
train
def bounding_box(self): """ An axis aligned bounding box for the current mesh. Returns ---------- aabb : trimesh.primitives.Box Box object with transform and extents defined representing the axis aligned bounding box of the mesh """ from . imp...
python
{ "resource": "" }
q23420
Geometry.bounding_box_oriented
train
def bounding_box_oriented(self): """ An oriented bounding box for the current mesh. Returns --------- obb : trimesh.primitives.Box Box object with transform and extents defined representing the minimum volume oriented bounding box of the mesh """ ...
python
{ "resource": "" }
q23421
Geometry.bounding_sphere
train
def bounding_sphere(self): """ A minimum volume bounding sphere for the current mesh. Note that the Sphere primitive returned has an unpadded, exact sphere_radius so while the distance of every vertex of the current mesh from sphere_center will be less than sphere_radius, the fa...
python
{ "resource": "" }
q23422
Geometry.bounding_cylinder
train
def bounding_cylinder(self): """ A minimum volume bounding cylinder for the current mesh. Returns -------- mincyl : trimesh.primitives.Cylinder Cylinder primitive containing current mesh """ from . import primitives, bounds kwargs = bounds.minim...
python
{ "resource": "" }
q23423
export_mesh
train
def export_mesh(mesh, file_obj, file_type=None, **kwargs): """ Export a Trimesh object to a file- like object, or to a filename Parameters --------- file_obj : str, file-like Where should mesh be exported to file_type : str or None Represents file type (eg: 'stl') Returns -...
python
{ "resource": "" }
q23424
export_off
train
def export_off(mesh, digits=10): """ Export a mesh as an OFF file, a simple text format Parameters ----------- mesh : trimesh.Trimesh Geometry to export digits : int Number of digits to include on floats Returns ----------- export : str OFF format output """ ...
python
{ "resource": "" }
q23425
export_dict
train
def export_dict(mesh, encoding=None): """ Export a mesh to a dict Parameters ------------ mesh : Trimesh object Mesh to be exported encoding : str, or None 'base64' Returns ------------- """ def encode(item, dtype=None): if encoding is No...
python
{ "resource": "" }
q23426
minify
train
def minify(path): """ Load a javascript file and minify. Parameters ------------ path: str, path of resource """ if 'http' in path: data = requests.get(path).content.decode( 'ascii', errors='ignore') else: with open(path, 'rb') as f: # some of th...
python
{ "resource": "" }
q23427
circle_pattern
train
def circle_pattern(pattern_radius, circle_radius, count, center=[0.0, 0.0], angle=None, **kwargs): """ Create a Path2D representing a circle pattern. Parameters ------------ pattern_radius : float R...
python
{ "resource": "" }
q23428
plane_transform
train
def plane_transform(origin, normal): """ Given the origin and normal of a plane find the transform that will move that plane to be coplanar with the XY plane. Parameters ---------- origin : (3,) float Point that lies on the plane normal : (3,) float Vector that points along ...
python
{ "resource": "" }
q23429
align_vectors
train
def align_vectors(a, b, return_angle=False): """ Find a transform between two 3D vectors. Implements the method described here: http://ethaneade.com/rot_between_vectors.pdf Parameters -------------- a : (3,) float Source vector b : (3,) float Target vector return_angle ...
python
{ "resource": "" }
q23430
vector_angle
train
def vector_angle(pairs): """ Find the angles between pairs of unit vectors. Parameters ---------- pairs : (n, 2, 3) float Unit vector pairs Returns ---------- angles : (n,) float Angles between vectors in radians """ pairs = np.asanyarray(pairs, dtype=np.float64) ...
python
{ "resource": "" }
q23431
triangulate_quads
train
def triangulate_quads(quads): """ Given a set of quad faces, return them as triangle faces. Parameters ----------- quads: (n, 4) int Vertex indices of quad faces Returns ----------- faces : (m, 3) int Vertex indices of triangular faces """ if len(quads) == 0: ...
python
{ "resource": "" }
q23432
mean_vertex_normals
train
def mean_vertex_normals(vertex_count, faces, face_normals, **kwargs): """ Find vertex normals from the mean of the faces that contain that vertex. Parameters ----------- vertex_count : int The number of vertices faces...
python
{ "resource": "" }
q23433
index_sparse
train
def index_sparse(column_count, indices): """ Return a sparse matrix for which vertices are contained in which faces. Returns --------- sparse: scipy.sparse.coo_matrix of shape (column_count, len(faces)) dtype is boolean Examples ---------- In [1]: sparse = faces_sparse(len...
python
{ "resource": "" }
q23434
get_json
train
def get_json(file_name='../dxf.json.template'): """ Load the JSON blob into native objects """ with open(file_name, 'r') as f: t = json.load(f) return t
python
{ "resource": "" }
q23435
write_json
train
def write_json(template, file_name='../dxf.json.template'): """ Write a native object to a JSON blob """ with open(file_name, 'w') as f: json.dump(template, f, indent=4)
python
{ "resource": "" }
q23436
replace_whitespace
train
def replace_whitespace(text, SAFE_SPACE='|<^>|', insert=True): """ Replace non-strippable whitepace in a string with a safe space """ if insert: # replace whitespace with safe space chr args = (' ', SAFE_SPACE) else: # replace safe space chr with whitespace args = (SA...
python
{ "resource": "" }
q23437
discretize_arc
train
def discretize_arc(points, close=False, scale=1.0): """ Returns a version of a three point arc consisting of line segments. Parameters --------- points : (3, d) float Points on the arc where d in [2,3] close : boolean If True close the arc ...
python
{ "resource": "" }
q23438
to_threepoint
train
def to_threepoint(center, radius, angles=None): """ For 2D arcs, given a center and radius convert them to three points on the arc. Parameters ----------- center : (2,) float Center point on the plane radius : float Radius of arc angles : (2,) float Angles in radians f...
python
{ "resource": "" }
q23439
abspath
train
def abspath(rel): """ Take paths relative to the current file and convert them to absolute paths. Parameters ------------ rel : str Relative path, IE '../stuff' Returns ------------- abspath : str Absolute path, IE '/home/user/stuff' """ retu...
python
{ "resource": "" }
q23440
load_pyassimp
train
def load_pyassimp(file_obj, file_type=None, resolver=None, **kwargs): """ Use the pyassimp library to load a mesh from a file object and type or file name if file_obj is a string Parameters --------- file_obj: str, or file object File ...
python
{ "resource": "" }
q23441
load_cyassimp
train
def load_cyassimp(file_obj, file_type=None, resolver=None, **kwargs): """ Load a file using the cyassimp bindings. The easiest way to install these is with conda: conda install -c menpo/label/master cyassimp Parameters --------- file_ob...
python
{ "resource": "" }
q23442
load_path
train
def load_path(obj, file_type=None, **kwargs): """ Load a file to a Path object. Parameters ----------- obj : One of the following: - Path, Path2D, or Path3D objects - open file object (dxf or svg) - file name (dxf or svg) - shapely.geometry.Polygon - sha...
python
{ "resource": "" }
q23443
_create_path
train
def _create_path(entities, vertices, metadata=None, **kwargs): """ Turn entities and vertices into a Path2D or a Path3D object depending on dimension of vertices. Parameters ----------- entities : list Entity objects that reference vert...
python
{ "resource": "" }
q23444
split_scene
train
def split_scene(geometry): """ Given a geometry, list of geometries, or a Scene return them as a single Scene object. Parameters ---------- geometry : splittable Returns --------- scene: trimesh.Scene """ # already a scene, so return it if util.is_instance_named(geometr...
python
{ "resource": "" }
q23445
append_scenes
train
def append_scenes(iterable, common=['world']): """ Concatenate multiple scene objects into one scene. Parameters ------------- iterable : (n,) Trimesh or Scene Geometries that should be appended common : (n,) str Nodes that shouldn't be remapped Returns ------------ r...
python
{ "resource": "" }
q23446
Scene.add_geometry
train
def add_geometry(self, geometry, node_name=None, geom_name=None, parent_node_name=None, transform=None): """ Add a geometry to the scene. If the mesh has multiple transforms defined in its ...
python
{ "resource": "" }
q23447
Scene.md5
train
def md5(self): """ MD5 of scene which will change when meshes or transforms are changed Returns -------- hashed: str, MD5 hash of scene """ # start with transforms hash hashes = [self.graph.md5()] for g in self.geometry.values(): ...
python
{ "resource": "" }
q23448
Scene.is_valid
train
def is_valid(self): """ Is every geometry connected to the root node. Returns ----------- is_valid : bool Does every geometry have a transform """ if len(self.geometry) == 0: return True try: referenced = {self.graph[i][...
python
{ "resource": "" }
q23449
Scene.bounds_corners
train
def bounds_corners(self): """ A list of points that represent the corners of the AABB of every geometry in the scene. This can be useful if you want to take the AABB in a specific frame. Returns ----------- corners: (n, 3) float, points in space ...
python
{ "resource": "" }
q23450
Scene.bounds
train
def bounds(self): """ Return the overall bounding box of the scene. Returns -------- bounds: (2,3) float points for min, max corner """ corners = self.bounds_corners bounds = np.array([corners.min(axis=0), corners.max(axis=0)]) ...
python
{ "resource": "" }
q23451
Scene.triangles
train
def triangles(self): """ Return a correctly transformed polygon soup of the current scene. Returns ---------- triangles: (n,3,3) float, triangles in space """ triangles = collections.deque() triangles_node = collections.deque() for node_n...
python
{ "resource": "" }
q23452
Scene.geometry_identifiers
train
def geometry_identifiers(self): """ Look up geometries by identifier MD5 Returns --------- identifiers: dict, identifier md5: key in self.geometry """ identifiers = {mesh.identifier_md5: name for name, mesh in self.geometry.items()} ...
python
{ "resource": "" }
q23453
Scene.duplicate_nodes
train
def duplicate_nodes(self): """ Return a sequence of node keys of identical meshes. Will combine meshes duplicated by copying in space with different keys in self.geometry, as well as meshes repeated by self.nodes. Returns ----------- duplicates: (m) sequence of ...
python
{ "resource": "" }
q23454
Scene.set_camera
train
def set_camera(self, angles=None, distance=None, center=None, resolution=None, fov=None): """ Create a camera object for self.camera, and add a transform to self.graph for it. If arguments are...
python
{ "resource": "" }
q23455
Scene.camera
train
def camera(self): """ Get the single camera for the scene. If not manually set one will abe automatically generated. Returns ---------- camera : trimesh.scene.Camera Camera object defined for the scene """ # no camera set for the scene yet ...
python
{ "resource": "" }
q23456
Scene.lights
train
def lights(self): """ Get a list of the lights in the scene. If nothing is set it will generate some automatically. Returns ------------- lights : [trimesh.scene.lighting.Light] Lights in the scene. """ if not hasattr(self, '_lights') or self._l...
python
{ "resource": "" }
q23457
Scene.rezero
train
def rezero(self): """ Move the current scene so that the AABB of the whole scene is centered at the origin. Does this by changing the base frame to a new, offset base frame. """ if self.is_empty or np.allclose(self.centroid, 0.0): # early exit since w...
python
{ "resource": "" }
q23458
Scene.dump
train
def dump(self): """ Append all meshes in scene to a list of meshes. Returns ---------- dumped: (n,) list, of Trimesh objects transformed to their location the scene.graph """ result = collections.deque() for node_name in self.g...
python
{ "resource": "" }
q23459
Scene.convex_hull
train
def convex_hull(self): """ The convex hull of the whole scene Returns --------- hull: Trimesh object, convex hull of all meshes in scene """ points = util.vstack_empty([m.vertices for m in self.dump()]) hull = convex.convex_hull(points) return hul...
python
{ "resource": "" }
q23460
Scene.export
train
def export(self, file_type=None): """ Export a snapshot of the current scene. Parameters ---------- file_type: what encoding to use for meshes ie: dict, dict64, stl Returns ---------- export: dict with keys: meshes: lis...
python
{ "resource": "" }
q23461
Scene.save_image
train
def save_image(self, resolution=(1024, 768), **kwargs): """ Get a PNG image of a scene. Parameters ----------- resolution: (2,) int, resolution to render image **kwargs: passed to SceneViewer constructor Returns ----------- png: bytes, render of...
python
{ "resource": "" }
q23462
Scene.units
train
def units(self): """ Get the units for every model in the scene, and raise a ValueError if there are mixed units. Returns ----------- units : str Units for every model in the scene """ existing = [i.units for i in self.geometry.values()] ...
python
{ "resource": "" }
q23463
Scene.units
train
def units(self, value): """ Set the units for every model in the scene without converting any units just setting the tag. Parameters ------------ value : str Value to set every geometry unit value to """ for m in self.geometry.values(): ...
python
{ "resource": "" }
q23464
Scene.convert_units
train
def convert_units(self, desired, guess=False): """ If geometry has units defined convert them to new units. Returns a new scene with geometries and transforms scaled. Parameters ---------- desired : str Desired final unit system: 'inches', 'mm', etc. g...
python
{ "resource": "" }
q23465
Scene.explode
train
def explode(self, vector=None, origin=None): """ Explode a scene around a point and vector. Parameters ----------- vector : (3,) float or float Explode radially around a direction vector or spherically origin : (3,) float Point to explode around ...
python
{ "resource": "" }
q23466
Scene.scaled
train
def scaled(self, scale): """ Return a copy of the current scene, with meshes and scene transforms scaled to the requested factor. Parameters ----------- scale : float Factor to scale meshes and transforms Returns ----------- scaled : tr...
python
{ "resource": "" }
q23467
Scene.copy
train
def copy(self): """ Return a deep copy of the current scene Returns ---------- copied : trimesh.Scene Copy of the current scene """ # use the geometries copy method to # allow them to handle references to unpickle-able objects geometry =...
python
{ "resource": "" }
q23468
Scene.show
train
def show(self, viewer=None, **kwargs): """ Display the current scene. Parameters ----------- viewer: str 'gl': open a pyglet window str,'notebook': return ipython.display.HTML None: automatically pick based on whether or not ...
python
{ "resource": "" }
q23469
available_formats
train
def available_formats(): """ Get a list of all available loaders Returns ----------- loaders : list Extensions of available loaders i.e. 'stl', 'ply', 'dxf', etc. """ loaders = mesh_formats() loaders.extend(path_formats()) loaders.extend(compressed_loaders.keys()) ...
python
{ "resource": "" }
q23470
load_mesh
train
def load_mesh(file_obj, file_type=None, resolver=None, **kwargs): """ Load a mesh file into a Trimesh object Parameters ----------- file_obj : str or file object File name or file with mesh data file_type : str or None Which file type, e.g. ...
python
{ "resource": "" }
q23471
load_compressed
train
def load_compressed(file_obj, file_type=None, resolver=None, mixed=False, **kwargs): """ Given a compressed archive load all the geometry that we can from it. Parameters ---------- file_obj : open file-like object ...
python
{ "resource": "" }
q23472
load_remote
train
def load_remote(url, **kwargs): """ Load a mesh at a remote URL into a local trimesh object. This must be called explicitly rather than automatically from trimesh.load to ensure users don't accidentally make network requests. Parameters ------------ url : string URL containing me...
python
{ "resource": "" }
q23473
load_kwargs
train
def load_kwargs(*args, **kwargs): """ Load geometry from a properly formatted dict or kwargs """ def handle_scene(): """ Load a scene from our kwargs: class: Scene geometry: dict, name: Trimesh kwargs graph: list of dict, kwargs for scene.graph.update...
python
{ "resource": "" }
q23474
parse_file_args
train
def parse_file_args(file_obj, file_type, resolver=None, **kwargs): """ Given a file_obj and a file_type try to turn them into a file-like object and a lowercase string of file type. Parameters ----------- file_obj: str: if string repr...
python
{ "resource": "" }
q23475
pack_rectangles
train
def pack_rectangles(rectangles, sheet_size, shuffle=False): """ Pack smaller rectangles onto a larger rectangle, using a binary space partition tree. Parameters ---------- rectangles : (n, 2) float An array of (width, height) pairs representing the rectangles to be packed. sheet...
python
{ "resource": "" }
q23476
pack_paths
train
def pack_paths(paths, sheet_size=None): """ Pack a list of Path2D objects into a rectangle. Parameters ------------ paths: (n,) Path2D Geometry to be packed Returns ------------ packed : trimesh.path.Path2D Object containing input geometry inserted : (m,) int Inde...
python
{ "resource": "" }
q23477
multipack
train
def multipack(polygons, sheet_size=None, iterations=50, density_escape=.95, spacing=0.094, quantity=None): """ Pack polygons into a rectangle by taking each Polygon's OBB and then packing that as a rectangle. Parameters ---------...
python
{ "resource": "" }
q23478
RectangleBin.insert
train
def insert(self, rectangle): """ Insert a rectangle into the bin. Parameters ------------- rectangle: (2,) float, size of rectangle to insert """ rectangle = np.asanyarray(rectangle, dtype=np.float64) for child in self.child: if child is not ...
python
{ "resource": "" }
q23479
RectangleBin.split
train
def split(self, length, vertical=True): """ Returns two bounding boxes representing the current bounds split into two smaller boxes. Parameters ------------- length: float, length to split vertical: bool, if True will split box vertically Returns ...
python
{ "resource": "" }
q23480
oriented_bounds_2D
train
def oriented_bounds_2D(points, qhull_options='QbB'): """ Find an oriented bounding box for an array of 2D points. Parameters ---------- points : (n,2) float Points in 2D. Returns ---------- transform : (3,3) float Homogenous 2D transformation matrix to move the input ...
python
{ "resource": "" }
q23481
corners
train
def corners(bounds): """ Given a pair of axis aligned bounds, return all 8 corners of the bounding box. Parameters ---------- bounds : (2,3) or (2,2) float Axis aligned bounds Returns ---------- corners : (8,3) float Corner vertices of the cube """ bounds = np....
python
{ "resource": "" }
q23482
contains
train
def contains(bounds, points): """ Do an axis aligned bounding box check on a list of points. Parameters ----------- bounds : (2, dimension) float Axis aligned bounding box points : (n, dimension) float Points in space Returns ----------- points_inside : (n,) bool ...
python
{ "resource": "" }
q23483
in_notebook
train
def in_notebook(): """ Check to see if we are in an IPython or Jypyter notebook. Returns ----------- in_notebook : bool Returns True if we are in a notebook """ try: # function returns IPython context, but only in IPython ipy = get_ipython() # NOQA # we only w...
python
{ "resource": "" }
q23484
_ScandinavianStemmer._r1_scandinavian
train
def _r1_scandinavian(self, word, vowels): """ Return the region R1 that is used by the Scandinavian stemmers. R1 is the region after the first non-vowel following a vowel, or is the null region at the end of the word if there is no such non-vowel. But then R1 is adjusted so that...
python
{ "resource": "" }
q23485
_StandardStemmer._r1r2_standard
train
def _r1r2_standard(self, word, vowels): """ Return the standard interpretations of the string regions R1 and R2. R1 is the region after the first non-vowel following a vowel, or is the null region at the end of the word if there is no such non-vowel. R2 is the region af...
python
{ "resource": "" }
q23486
_StandardStemmer._rv_standard
train
def _rv_standard(self, word, vowels): """ Return the standard interpretation of the string region RV. If the second letter is a consonant, RV is the region after the next following vowel. If the first two letters are vowels, RV is the region after the next following consonant. O...
python
{ "resource": "" }
q23487
FrenchStemmer.__rv_french
train
def __rv_french(self, word, vowels): """ Return the region RV that is used by the French stemmer. If the word begins with two vowels, RV is the region after the third letter. Otherwise, it is the region after the first vowel not at the beginning of the word, or the end of the wo...
python
{ "resource": "" }
q23488
HungarianStemmer.__r1_hungarian
train
def __r1_hungarian(self, word, vowels, digraphs): """ Return the region R1 that is used by the Hungarian stemmer. If the word begins with a vowel, R1 is defined as the region after the first consonant or digraph (= two letters stand for one phoneme) in the word. If the word begi...
python
{ "resource": "" }
q23489
RussianStemmer.__regions_russian
train
def __regions_russian(self, word): """ Return the regions RV and R2 which are used by the Russian stemmer. In any word, RV is the region after the first vowel, or the end of the word if it contains no vowel. R2 is the region after the first non-vowel following a vowel i...
python
{ "resource": "" }
q23490
RussianStemmer.__cyrillic_to_roman
train
def __cyrillic_to_roman(self, word): """ Transliterate a Russian word into the Roman alphabet. A Russian word whose letters consist of the Cyrillic alphabet are transliterated into the Roman alphabet in order to ease the forthcoming stemming process. :param word: The wo...
python
{ "resource": "" }
q23491
RussianStemmer.__roman_to_cyrillic
train
def __roman_to_cyrillic(self, word): """ Transliterate a Russian word back into the Cyrillic alphabet. A Russian word formerly transliterated into the Roman alphabet in order to ease the stemming process, is transliterated back into the Cyrillic alphabet, its original form. ...
python
{ "resource": "" }
q23492
SwedishStemmer.stem
train
def stem(self, word): """ Stem a Swedish word and return the stemmed form. :param word: The word that is stemmed. :type word: str or unicode :return: The stemmed form. :rtype: unicode """ word = word.lower() r1 = self._r1_scandinavian(word, self...
python
{ "resource": "" }
q23493
deaccent
train
def deaccent(text): """ Remove accentuation from the given string. """ norm = unicodedata.normalize("NFD", text) result = "".join(ch for ch in norm if unicodedata.category(ch) != 'Mn') return unicodedata.normalize("NFC", result)
python
{ "resource": "" }
q23494
tokenize
train
def tokenize(text, lowercase=False, deacc=False): """ Iteratively yield tokens as unicode strings, optionally also lowercasing them and removing accent marks. """ if lowercase: text = text.lower() if deacc: text = deaccent(text) for match in PAT_ALPHABETIC.finditer(text): ...
python
{ "resource": "" }
q23495
clean_text_by_sentences
train
def clean_text_by_sentences(text, language="english", additional_stopwords=None): """ Tokenizes a given text into sentences, applying filters and lemmatizing them. Returns a SyntacticUnit list. """ init_textcleanner(language, additional_stopwords) original_sentences = split_sentences(text) filtered_...
python
{ "resource": "" }
q23496
clean_text_by_word
train
def clean_text_by_word(text, language="english", deacc=False, additional_stopwords=None): """ Tokenizes a given text into words, applying filters and lemmatizing them. Returns a dict of word -> syntacticUnit. """ init_textcleanner(language, additional_stopwords) text_without_acronyms = replace_with_sepa...
python
{ "resource": "" }
q23497
_get_sentences_with_word_count
train
def _get_sentences_with_word_count(sentences, words): """ Given a list of sentences, returns a list of sentences with a total word count similar to the word count provided. """ word_count = 0 selected_sentences = [] # Loops until the word count is reached. for sentence in sentences: ...
python
{ "resource": "" }
q23498
pagerank_weighted
train
def pagerank_weighted(graph, initial_value=None, damping=0.85): """Calculates PageRank for an undirected graph""" if initial_value == None: initial_value = 1.0 / len(graph.nodes()) scores = dict.fromkeys(graph.nodes(), initial_value) iteration_quantity = 0 for iteration_number in range(100): ...
python
{ "resource": "" }
q23499
Env.db_url
train
def db_url(self, var=DEFAULT_DATABASE_ENV, default=NOTSET, engine=None): """Returns a config dictionary, defaulting to DATABASE_URL. :rtype: dict """ return self.db_url_config(self.get_value(var, default=default), engine=engine)
python
{ "resource": "" }