idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
35,200 | def validate_offset ( reference_event , estimated_event , t_collar = 0.200 , percentage_of_length = 0.5 ) : if 'event_offset' in reference_event and 'event_offset' in estimated_event : annotated_length = reference_event [ 'event_offset' ] - reference_event [ 'event_onset' ] return math . fabs ( reference_event [ 'event... | Validate estimated event based on event offset |
35,201 | def load_event_list ( filename , ** kwargs ) : return dcase_util . containers . MetaDataContainer ( ) . load ( filename = filename , ** kwargs ) | Load event list from csv formatted text - file |
35,202 | def load_scene_list ( filename , ** kwargs ) : return dcase_util . containers . MetaDataContainer ( ) . load ( filename = filename , ** kwargs ) | Load scene list from csv formatted text - file |
35,203 | def load_file_pair_list ( filename ) : data = [ ] input_file = open ( filename , 'rt' ) try : dialect = csv . Sniffer ( ) . sniff ( input_file . readline ( ) , [ ',' , ';' , '\t' ] ) except csv . Error : raise ValueError ( 'Unknown delimiter in file [{file}].' . format ( file = filename ) ) input_file . seek ( 0 ) for ... | Load file pair list csv formatted text - file |
35,204 | def class_wise_accuracy ( self , scene_label ) : if len ( self . accuracies_per_class . shape ) == 2 : return { 'accuracy' : float ( numpy . mean ( self . accuracies_per_class [ : , self . scene_label_list . index ( scene_label ) ] ) ) } else : return { 'accuracy' : float ( numpy . mean ( self . accuracies_per_class [ ... | Class - wise accuracy |
35,205 | def unique_scene_labels ( scene_list ) : if isinstance ( scene_list , dcase_util . containers . MetaDataContainer ) : return scene_list . unique_scene_labels else : labels = [ ] for item in scene_list : if 'scene_label' in item and item [ 'scene_label' ] not in labels : labels . append ( item [ 'scene_label' ] ) labels... | Find the unique scene labels |
35,206 | def event_list_to_event_roll ( source_event_list , event_label_list = None , time_resolution = 0.01 ) : if isinstance ( source_event_list , dcase_util . containers . MetaDataContainer ) : max_offset_value = source_event_list . max_offset if event_label_list is None : event_label_list = source_event_list . unique_event_... | Convert event list into event roll binary activity matrix |
35,207 | def pad_event_roll ( event_roll , length ) : if length > event_roll . shape [ 0 ] : padding = numpy . zeros ( ( length - event_roll . shape [ 0 ] , event_roll . shape [ 1 ] ) ) event_roll = numpy . vstack ( ( event_roll , padding ) ) return event_roll | Pad event roll s length to given length |
35,208 | def match_event_roll_lengths ( event_roll_a , event_roll_b , length = None ) : if length is None : length = max ( event_roll_b . shape [ 0 ] , event_roll_a . shape [ 0 ] ) else : length = int ( length ) if length < event_roll_a . shape [ 0 ] : event_roll_a = event_roll_a [ 0 : length , : ] else : event_roll_a = pad_eve... | Fix the length of two event rolls |
35,209 | def filter_event_list ( event_list , scene_label = None , event_label = None , filename = None ) : return dcase_util . containers . MetaDataContainer ( event_list ) . filter ( filename = filename , scene_label = scene_label , event_label = event_label ) | Filter event list based on given fields |
35,210 | def unique_files ( event_list ) : if isinstance ( event_list , dcase_util . containers . MetaDataContainer ) : return event_list . unique_files else : files = { } for event in event_list : if 'file' in event : files [ event [ 'file' ] ] = event [ 'file' ] elif 'filename' in event : files [ event [ 'filename' ] ] = even... | Find the unique files |
35,211 | def unique_event_labels ( event_list ) : if isinstance ( event_list , dcase_util . containers . MetaDataContainer ) : return event_list . unique_event_labels else : labels = [ ] for event in event_list : if 'event_label' in event and event [ 'event_label' ] not in labels : labels . append ( event [ 'event_label' ] ) la... | Find the unique event labels |
35,212 | def __getChannelId ( self ) : if not self . search_params . get ( "channelId" ) : return api_fixed_url = "https://www.googleapis.com/youtube/v3/channels?part=id&maxResults=1&fields=items%2Fid&" url = api_fixed_url + urlencode ( { "key" : self . api_key , "forUsername" : self . search_params [ "channelId" ] } ) get = re... | Obtain channel id for channel name if present in self . search_params . |
35,213 | def __searchParser ( self , query ) : ret = dict ( ) parse_params = True buf = "" ptr = "" p_avail = ( "channel" , "max" , "before" , "after" , "order" ) opts = dict ( ) par_open = False translate = { 'a' : 'audio' , 'v' : 'video' , 'f' : 'format' , 's' : 'stream' , 'P' : 'stream' , 'm' : 'metadata' , 'max' : 'maxResul... | Parse query for advanced search options . |
35,214 | def __search ( self , pt = "" ) : if not self . search_params . get ( 'q' ) and not self . search_params . get ( 'channelId' ) : return { 'items' : [ ] } api_fixed_url = "https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&fields=items(id%2Ckind%2Csnippet)%2CnextPageToken%2CprevPageToken&" d = { "key" ... | Method responsible for searching using YouTube API . |
35,215 | def clean ( self ) : for s in self . visible_files . values ( ) : s . clean ( ) for s in [ sub [ 1 ] [ x ] for sub in self . avail_files . values ( ) for x in sub [ 1 ] ] : s . clean ( ) | Clear the data . For each YTStor object present in this object clean method is executed . |
35,216 | def obtainInfo ( self ) : try : info = self . ytdl . extract_info ( self . yid , download = False ) except youtube_dl . utils . DownloadError : raise ConnectionError if not self . preferences [ 'stream' ] : self . url = ( info [ 'requested_formats' ] [ 0 ] [ 'url' ] , info [ 'requested_formats' ] [ 1 ] [ 'url' ] ) retu... | Method for obtaining information about the movie . |
35,217 | def registerHandler ( self , fh ) : self . fds . add ( fh ) self . atime = int ( time ( ) ) self . lock . acquire ( ) try : if ( 0 , self . filesize ) not in self . avail and self . preferences [ 'stream' ] is False : Downloader . fetch ( self , None , fh ) except requests . exceptions . ConnectionError : raise Connect... | Register new file descriptor . |
35,218 | def read ( self , offset , length , fh ) : current = ( offset , offset + length ) safe = [ current [ 0 ] - ( 8 * length ) , current [ 1 ] + ( 16 * length ) ] if safe [ 0 ] < 0 : safe [ 0 ] = 0 if safe [ 1 ] > self . filesize : safe [ 1 ] = self . filesize safe = tuple ( safe ) self . lock . acquire ( ) try : dl = range... | Read data . Method returns data instantly if they re avaialable and in self . safe_range . Otherwise data is downloaded and then returned . |
35,219 | def clean ( self ) : self . closing = True if not self . fds : self . data . close ( ) | Clear data . Explicitly close self . data if object is unused . |
35,220 | def unregisterHandler ( self , fh ) : try : self . fds . remove ( fh ) except KeyError : pass self . lock . acquire ( ) try : self . data . rollover ( ) finally : self . lock . release ( ) if self . closing and not self . fds : self . data . close ( ) | Unregister a file descriptor . Clean data if such operation has been scheduled . |
35,221 | def push ( self , yts ) : if not isinstance ( yts , ( YTStor , YTMetaStor , type ( None ) ) ) : raise TypeError ( "Expected YTStor object, YTMetaStor object or None." ) k = 0 while k in self . keys ( ) : k += 1 self [ k ] = yts return k | Search for add and return new file descriptor . |
35,222 | def __pathToTuple ( self , path ) : if not path or path . count ( '/' ) > 2 : raise YTFS . PathConvertError ( "Bad path given" ) try : split = path . split ( '/' ) except ( AttributeError , TypeError ) : raise TypeError ( "Path has to be string" ) if split [ 0 ] : raise YTFS . PathConvertError ( "Path needs to start wi... | Convert directory or file path to its tuple identifier . |
35,223 | def __exists ( self , p ) : try : p = self . __pathToTuple ( p ) except TypeError : pass return ( ( not p [ 0 ] and not p [ 1 ] ) or ( p [ 0 ] in self . searches and not p [ 1 ] ) or ( p [ 0 ] in self . searches and p [ 1 ] in self . searches [ p [ 0 ] ] ) ) | Check if file of given path exists . |
35,224 | def _pathdec ( method ) : @ wraps ( method ) def mod ( self , path , * args ) : try : return method ( self , self . __pathToTuple ( path ) , * args ) except YTFS . PathConvertError : raise FuseOSError ( errno . EINVAL ) return mod | Decorator that replaces string path argument with its tuple identifier . |
35,225 | def getattr ( self , tid , fh = None ) : if not self . __exists ( tid ) : raise FuseOSError ( errno . ENOENT ) pt = self . PathType . get ( tid ) st = deepcopy ( self . st ) st [ 'st_atime' ] = int ( time ( ) ) st [ 'st_mtime' ] = st [ 'st_atime' ] st [ 'st_ctime' ] = st [ 'st_atime' ] if pt is self . PathType . file :... | File attributes . |
35,226 | def readdir ( self , tid , fh ) : ret = [ ] pt = self . PathType . get ( tid ) try : if pt is self . PathType . main : ret = list ( self . searches ) elif pt is self . PathType . subdir : ret = list ( self . searches [ tid [ 0 ] ] ) elif pt is self . PathType . file : raise FuseOSError ( errno . ENOTDIR ) else : raise ... | Read directory contents . Lists visible elements of YTActions object . |
35,227 | def mkdir ( self , tid , mode ) : pt = self . PathType . get ( tid ) if pt is self . PathType . invalid or pt is self . PathType . file : raise FuseOSError ( errno . EPERM ) if self . __exists ( tid ) : raise FuseOSError ( errno . EEXIST ) try : dir_ent = YTActions ( tid [ 0 ] ) dir_ent . updateResults ( ) except Conne... | Directory creation . Search is performed . |
35,228 | def rename ( self , old , new ) : new = self . __pathToTuple ( new ) if not self . __exists ( old ) : raise FuseOSError ( errno . ENOENT ) if self . PathType . get ( old ) is not self . PathType . subdir or self . PathType . get ( new ) is not self . PathType . subdir : raise FuseOSError ( errno . EPERM ) if self . __e... | Directory renaming support . Needed because many file managers create directories with default names wich makes it impossible to perform a search without CLI . Name changes for files are not allowed only for directories . |
35,229 | def rmdir ( self , tid ) : pt = self . PathType . get ( tid ) if pt is self . PathType . main : raise FuseOSError ( errno . EINVAL ) elif pt is not self . PathType . subdir : raise FuseOSError ( errno . ENOTDIR ) try : self . searches [ tid [ 0 ] ] . clean ( ) del self . searches [ tid [ 0 ] ] except KeyError : raise F... | Directory removal . YTActions object under tid is told to clean all data and then it is deleted . |
35,230 | def open ( self , tid , flags ) : pt = self . PathType . get ( tid ) if pt is not self . PathType . file and pt is not self . PathType . ctrl : raise FuseOSError ( errno . EINVAL ) if pt is not self . PathType . ctrl and ( flags & os . O_WRONLY or flags & os . O_RDWR ) : raise FuseOSError ( errno . EPERM ) if not self ... | File open . YTStor object associated with this file is initialised and written to self . fds . |
35,231 | def write ( self , tid , data , offset , fh ) : if tid [ 1 ] == " next" : d = True elif tid [ 1 ] == " prev" : d = False else : raise FuseOSError ( errno . EPERM ) try : self . searches [ tid [ 0 ] ] . updateResults ( d ) except KeyError : raise FuseOSError ( errno . EINVAL ) except ConnectionError : raise FuseOSError ... | Write operation . Applicable only for control files - updateResults is called . |
35,232 | def release ( self , tid , fh ) : try : try : self . fds [ fh ] . unregisterHandler ( fh ) except AttributeError : pass del self . fds [ fh ] except KeyError : raise FuseOSError ( errno . EBADF ) return 0 | Close file . Descriptor is removed from self . fds . |
35,233 | def __match_l ( self , k , _set ) : return { r for r in _set if k [ 0 ] in range ( * r ) or k [ 1 ] in range ( * r ) or ( k [ 0 ] < r [ 0 ] and k [ 1 ] >= r [ 1 ] ) } | Method for searching subranges from _set that overlap on k range . |
35,234 | def contains ( self , val ) : ( start , end ) = self . __val_convert ( val ) retlen = 0 for r in self . __has : if start < r [ 1 ] and end > r [ 0 ] : retlen += ( ( end < r [ 1 ] and end ) or r [ 1 ] ) - ( ( start > r [ 0 ] and start ) or r [ 0 ] ) return retlen | Check if given value or range is present . |
35,235 | def __add ( self , val ) : if not isinstance ( val , range_t ) : val = { self . __val_convert ( val ) } else : val = val . toset ( ) __has = deepcopy ( self . __has ) __has . update ( val ) return __has | Helper method for range addition . It is allowed to add only one compact subrange or range_t object at once . |
35,236 | def done ( self , warn = True ) : if not self . process : raise Exception ( "Not implemented yet or process not started yet, make sure to overload the done() method in your Experiment class" ) self . process . poll ( ) if self . process . returncode == None : return False elif self . process . returncode > 0 : raise Pr... | Is the subprocess done? |
35,237 | def getalignedtarget ( self , index ) : targetindices = [ ] target = None foundindex = - 1 for sourceindex , targetindex in self . alignment : if sourceindex == index : targetindices . append ( targetindex ) if len ( targetindices ) > 1 : for i in range ( 1 , len ( targetindices ) ) : if abs ( targetindices [ i ] - tar... | Returns target range only if source index aligns to a single consecutive range of target tokens . |
35,238 | def targetword ( self , index , targetwords , alignment ) : if alignment [ index ] : return targetwords [ alignment [ index ] ] else : return None | Return the aligned targetword for a specified index in the source words |
35,239 | def targetwords ( self , index , targetwords , alignment ) : return [ targetwords [ x ] for x in alignment [ index ] ] | Return the aligned targetwords for a specified index in the source words |
35,240 | def sum_to_n ( n , size , limit = None ) : if size == 1 : yield [ n ] return if limit is None : limit = n start = ( n + size - 1 ) // size stop = min ( limit , n - size + 1 ) + 1 for i in range ( start , stop ) : for tail in sum_to_n ( n - i , size - 1 , i ) : yield [ i ] + tail | Produce all lists of size positive integers in decreasing order that add up to n . |
35,241 | def nfa ( self , nextstate ) : if self . interval : mininterval , maxinterval = self . interval nextstate2 = nextstate for i in range ( maxinterval ) : state = State ( transitions = [ ( self , self . match , nextstate2 ) ] ) if i + 1 > mininterval : if nextstate is not nextstate2 : state . transitions . append ( ( self... | Returns an initial state for an NFA |
35,242 | def nfa ( self ) : finalstate = State ( final = True ) nextstate = finalstate for tokenexpr in reversed ( self ) : state = tokenexpr . nfa ( nextstate ) nextstate = state return NFA ( state ) | convert the expression into an NFA |
35,243 | def stddev ( values , meanval = None ) : if meanval == None : meanval = mean ( values ) return math . sqrt ( sum ( [ ( x - meanval ) ** 2 for x in values ] ) / ( len ( values ) - 1 ) ) | The standard deviation of a set of values . Pass in the mean if you already know it . |
35,244 | def save ( self , filename , addnormalised = False ) : f = io . open ( filename , 'w' , encoding = 'utf-8' ) for line in self . output ( "\t" , addnormalised ) : f . write ( line + '\n' ) f . close ( ) | Save a frequency list to file can be loaded later using the load method |
35,245 | def output ( self , delimiter = '\t' , addnormalised = False ) : for type , count in self : if isinstance ( type , tuple ) or isinstance ( type , list ) : if addnormalised : yield " " . join ( ( u ( x ) for x in type ) ) + delimiter + str ( count ) + delimiter + str ( count / self . total ) else : yield " " . join ( ( ... | Print a representation of the frequency list |
35,246 | def entropy ( self , base = 2 ) : entropy = 0 if not base and self . base : base = self . base for type in self . _dist : if not base : entropy += self . _dist [ type ] * - math . log ( self . _dist [ type ] ) else : entropy += self . _dist [ type ] * - math . log ( self . _dist [ type ] , base ) return entropy | Compute the entropy of the distribution |
35,247 | def output ( self , delimiter = '\t' , freqlist = None ) : for type , prob in self : if freqlist : if isinstance ( type , list ) or isinstance ( type , tuple ) : yield " " . join ( type ) + delimiter + str ( freqlist [ type ] ) + delimiter + str ( prob ) else : yield type + delimiter + str ( freqlist [ type ] ) + delim... | Generator yielding formatted strings expressing the time and probabily for each item in the distribution |
35,248 | def process ( self , sourcewords , debug = False ) : if isinstance ( sourcewords , list ) or isinstance ( sourcewords , tuple ) : sourcewords_s = " " . join ( sourcewords ) else : sourcewords_s = sourcewords sourcewords = sourcewords . split ( ' ' ) self . socket . sendall ( sourcewords_s . encode ( self . encoding ) +... | Process a list of words passing it to the server and realigning the output with the original words |
35,249 | def checkversion ( version , REFVERSION = FOLIAVERSION ) : try : for refversion , docversion in zip ( [ int ( x ) for x in REFVERSION . split ( '.' ) ] , [ int ( x ) for x in version . split ( '.' ) ] ) : if docversion > refversion : return 1 elif docversion < refversion : return - 1 return 0 except ValueError : raise ... | Checks FoLiA version returns 1 if the document is newer than the library - 1 if it is older 0 if it is equal |
35,250 | def xmltreefromstring ( s ) : if sys . version < '3' : if isinstance ( s , unicode ) : s = s . encode ( 'utf-8' ) try : return ElementTree . parse ( StringIO ( s ) , ElementTree . XMLParser ( collect_ids = False ) ) except TypeError : return ElementTree . parse ( StringIO ( s ) , ElementTree . XMLParser ( ) ) else : if... | Internal function deals with different Python versions unicode strings versus bytes and with the leak bug in lxml |
35,251 | def xmltreefromfile ( filename ) : try : return ElementTree . parse ( filename , ElementTree . XMLParser ( collect_ids = False ) ) except TypeError : return ElementTree . parse ( filename , ElementTree . XMLParser ( ) ) | Internal function to read an XML file |
35,252 | def commonancestors ( Class , * args ) : commonancestors = None for sibling in args : ancestors = list ( sibling . ancestors ( Class ) ) if commonancestors is None : commonancestors = copy ( ancestors ) else : removeancestors = [ ] for a in commonancestors : if not a in ancestors : removeancestors . append ( a ) for a ... | Generator function to find common ancestors of a particular type for any two or more FoLiA element instances . |
35,253 | def description ( self ) : for e in self : if isinstance ( e , Description ) : return e . value raise NoSuchAnnotation | Obtain the description associated with the element . |
35,254 | def findcorrectionhandling ( self , cls ) : if cls == "current" : return CorrectionHandling . CURRENT elif cls == "original" : return CorrectionHandling . ORIGINAL else : correctionhandling = None for correction in self . select ( Correction ) : found = False hastext = False if correction . hasnew ( ) : found = True do... | Find the proper correctionhandling given a textclass by looking in the underlying corrections where it is reused |
35,255 | def textvalidation ( self , warnonly = None ) : if warnonly is None and self . doc and self . doc . version : warnonly = ( checkversion ( self . doc . version , '1.5.0' ) < 0 ) valid = True for cls in self . doc . textclasses : if self . hastext ( cls , strict = True ) and not isinstance ( self , ( Linebreak , Whitespa... | Run text validation on this element . Checks whether any text redundancy is consistent and whether offsets are valid . |
35,256 | def speech_speaker ( self ) : if self . speaker : return self . speaker elif self . parent : return self . parent . speech_speaker ( ) else : return None | Retrieves the speaker of the audio or video file associated with the element . |
35,257 | def feat ( self , subset ) : r = None for f in self : if isinstance ( f , Feature ) and f . subset == subset : if r : if isinstance ( r , list ) : r . append ( f . cls ) else : r = [ r , f . cls ] else : r = f . cls if r is None : raise NoSuchAnnotation else : return r | Obtain the feature class value of the specific subset . |
35,258 | def copy ( self , newdoc = None , idsuffix = "" ) : if idsuffix is True : idsuffix = ".copy." + "%08x" % random . getrandbits ( 32 ) c = deepcopy ( self ) if idsuffix : c . addidsuffix ( idsuffix ) c . setparents ( ) c . setdoc ( newdoc ) return c | Make a deep copy of this element and all its children . |
35,259 | def copychildren ( self , newdoc = None , idsuffix = "" ) : if idsuffix is True : idsuffix = ".copy." + "%08x" % random . getrandbits ( 32 ) for c in self : if isinstance ( c , AbstractElement ) : yield c . copy ( newdoc , idsuffix ) | Generator creating a deep copy of the children of this element . |
35,260 | def public ( self ) : return bool ( lib . EnvSlotPublicP ( self . _env , self . _cls , self . _name ) ) | True if the Slot is public . |
35,261 | def initializable ( self ) : return bool ( lib . EnvSlotInitableP ( self . _env , self . _cls , self . _name ) ) | True if the Slot is initializable . |
35,262 | def writable ( self ) : return bool ( lib . EnvSlotWritableP ( self . _env , self . _cls , self . _name ) ) | True if the Slot is writable . |
35,263 | def accessible ( self ) : return bool ( lib . EnvSlotDirectAccessP ( self . _env , self . _cls , self . _name ) ) | True if the Slot is directly accessible . |
35,264 | def sources ( self ) : data = clips . data . DataObject ( self . _env ) lib . EnvSlotSources ( self . _env , self . _cls , self . _name , data . byref ) return tuple ( data . value ) if isinstance ( data . value , list ) else ( ) | A tuple containing the names of the Class sources for this Slot . |
35,265 | def facets ( self ) : data = clips . data . DataObject ( self . _env ) lib . EnvSlotFacets ( self . _env , self . _cls , self . _name , data . byref ) return tuple ( data . value ) if isinstance ( data . value , list ) else ( ) | A tuple containing the facets for this Slot . |
35,266 | def allowed_classes ( self ) : data = clips . data . DataObject ( self . _env ) lib . EnvSlotAllowedClasses ( self . _env , self . _cls , self . _name , data . byref ) if isinstance ( data . value , list ) : for klass in classes ( self . _env , data . value ) : yield klass | Iterate over the allowed classes for this slot . |
35,267 | def name ( self ) : return ffi . string ( lib . EnvGetInstanceName ( self . _env , self . _ist ) ) . decode ( ) | Instance name . |
35,268 | def instance_class ( self ) : return Class ( self . _env , lib . EnvGetInstanceClass ( self . _env , self . _ist ) ) | Instance class . |
35,269 | def send ( self , message , arguments = None ) : output = clips . data . DataObject ( self . _env ) instance = clips . data . DataObject ( self . _env , dtype = CLIPSType . INSTANCE_ADDRESS ) instance . value = self . _ist args = arguments . encode ( ) if arguments is not None else ffi . NULL lib . EnvSend ( self . _en... | Send a message to the Instance . |
35,270 | def delete ( self ) : if lib . EnvDeleteInstance ( self . _env , self . _ist ) != 1 : raise CLIPSError ( self . _env ) | Delete the instance . |
35,271 | def unmake ( self ) : if lib . EnvUnmakeInstance ( self . _env , self . _ist ) != 1 : raise CLIPSError ( self . _env ) | This method is equivalent to delete except that it uses message - passing instead of directly deleting the instance . |
35,272 | def name ( self ) : return ffi . string ( lib . EnvGetDefmessageHandlerName ( self . _env , self . _cls , self . _idx ) ) . decode ( ) | MessageHandler name . |
35,273 | def type ( self ) : return ffi . string ( lib . EnvGetDefmessageHandlerType ( self . _env , self . _cls , self . _idx ) ) . decode ( ) | MessageHandler type . |
35,274 | def deletable ( self ) : return bool ( lib . EnvIsDefmessageHandlerDeletable ( self . _env , self . _cls , self . _idx ) ) | True if the MessageHandler can be deleted . |
35,275 | def undefine ( self ) : if lib . EnvUndefmessageHandler ( self . _env , self . _cls , self . _idx ) != 1 : raise CLIPSError ( self . _env ) self . _env = None | Undefine the MessageHandler . |
35,276 | def load ( self , path ) : try : self . _load_binary ( path ) except CLIPSError : self . _load_text ( path ) | Load a set of constructs into the CLIPS data base . |
35,277 | def save ( self , path , binary = False ) : if binary : ret = lib . EnvBsave ( self . _env , path . encode ( ) ) else : ret = lib . EnvSave ( self . _env , path . encode ( ) ) if ret == 0 : raise CLIPSError ( self . _env ) | Save a set of constructs into the CLIPS data base . |
35,278 | def batch_star ( self , path ) : if lib . EnvBatchStar ( self . _env , path . encode ( ) ) != 1 : raise CLIPSError ( self . _env ) | Evaluate the commands contained in the specific path . |
35,279 | def build ( self , construct ) : if lib . EnvBuild ( self . _env , construct . encode ( ) ) != 1 : raise CLIPSError ( self . _env ) | Build a single construct in CLIPS . |
35,280 | def eval ( self , construct ) : data = clips . data . DataObject ( self . _env ) if lib . EnvEval ( self . _env , construct . encode ( ) , data . byref ) != 1 : raise CLIPSError ( self . _env ) return data . value | Evaluate an expression returning its value . |
35,281 | def define_function ( self , function , name = None ) : name = name if name is not None else function . __name__ ENVIRONMENT_DATA [ self . _env ] . user_functions [ name ] = function self . build ( DEFFUNCTION . format ( name ) ) | Define the Python function within the CLIPS environment . |
35,282 | def activate ( self ) : if lib . EnvActivateRouter ( self . _env , self . _name . encode ( ) ) == 0 : raise RuntimeError ( "Unable to activate router %s" % self . _name ) | Activate the Router . |
35,283 | def deactivate ( self ) : if lib . EnvDeactivateRouter ( self . _env , self . _name . encode ( ) ) == 0 : raise RuntimeError ( "Unable to deactivate router %s" % self . _name ) | Deactivate the Router . |
35,284 | def delete ( self ) : if lib . EnvDeleteRouter ( self . _env , self . _name . encode ( ) ) == 0 : raise RuntimeError ( "Unable to delete router %s" % self . _name ) | Delete the Router . |
35,285 | def add_to_environment ( self , environment ) : self . _env = environment . _env self . _userdata = ffi . new_handle ( self ) ENVIRONMENT_DATA [ self . _env ] . routers [ self . name ] = self lib . EnvAddRouterWithContext ( self . _env , self . _name . encode ( ) , self . _priority , lib . query_function , lib . print_... | Add the router to the given environment . |
35,286 | def value ( self ) : dtype = lib . get_data_type ( self . _data ) dvalue = lib . get_data_value ( self . _data ) if dvalue == ffi . NULL : return None return self . python_value ( dtype , dvalue ) | Return the DATA_OBJECT stored value . |
35,287 | def value ( self , value ) : dtype = TYPES [ type ( value ) ] if self . _type is None else self . _type lib . set_data_type ( self . _data , dtype ) lib . set_data_value ( self . _data , self . clips_value ( value ) ) | Sets the DATA_OBJECT stored value . |
35,288 | def python_value ( self , dtype , dvalue ) : try : return CONVERTERS [ dtype ] ( dvalue ) except KeyError : if dtype == clips . common . CLIPSType . MULTIFIELD : return self . multifield_to_list ( ) if dtype == clips . common . CLIPSType . FACT_ADDRESS : return clips . facts . new_fact ( self . _env , lib . to_pointer ... | Convert a CLIPS type into Python . |
35,289 | def clips_value ( self , dvalue ) : try : return VALUES [ type ( dvalue ) ] ( self . _env , dvalue ) except KeyError : if isinstance ( dvalue , ( list , tuple ) ) : return self . list_to_multifield ( dvalue ) if isinstance ( dvalue , ( clips . facts . Fact ) ) : return dvalue . _fact if isinstance ( dvalue , ( clips . ... | Convert a Python type into CLIPS . |
35,290 | def agenda_changed ( self ) : value = bool ( lib . EnvGetAgendaChanged ( self . _env ) ) lib . EnvSetAgendaChanged ( self . _env , int ( False ) ) return value | True if any rule activation changes have occurred . |
35,291 | def rules ( self ) : rule = lib . EnvGetNextDefrule ( self . _env , ffi . NULL ) while rule != ffi . NULL : yield Rule ( self . _env , rule ) rule = lib . EnvGetNextDefrule ( self . _env , rule ) | Iterate over the defined Rules . |
35,292 | def find_rule ( self , rule ) : defrule = lib . EnvFindDefrule ( self . _env , rule . encode ( ) ) if defrule == ffi . NULL : raise LookupError ( "Rule '%s' not found" % defrule ) return Rule ( self . _env , defrule ) | Find a Rule by name . |
35,293 | def reorder ( self , module = None ) : module = module . _mdl if module is not None else ffi . NULL lib . EnvReorderAgenda ( self . _env , module ) | Reorder the Activations in the Agenda . |
35,294 | def refresh ( self , module = None ) : module = module . _mdl if module is not None else ffi . NULL lib . EnvRefreshAgenda ( self . _env , module ) | Recompute the salience values of the Activations on the Agenda and then reorder the agenda . |
35,295 | def activations ( self ) : activation = lib . EnvGetNextActivation ( self . _env , ffi . NULL ) while activation != ffi . NULL : yield Activation ( self . _env , activation ) activation = lib . EnvGetNextActivation ( self . _env , activation ) | Iterate over the Activations in the Agenda . |
35,296 | def clear ( self ) : if lib . EnvDeleteActivation ( self . _env , ffi . NULL ) != 1 : raise CLIPSError ( self . _env ) | Deletes all activations in the agenda . |
35,297 | def name ( self ) : return ffi . string ( lib . EnvGetDefruleName ( self . _env , self . _rule ) ) . decode ( ) | Rule name . |
35,298 | def module ( self ) : modname = ffi . string ( lib . EnvDefruleModule ( self . _env , self . _rule ) ) defmodule = lib . EnvFindDefmodule ( self . _env , modname ) return Module ( self . _env , defmodule ) | The module in which the Rule is defined . |
35,299 | def watch_firings ( self , flag ) : lib . EnvSetDefruleWatchFirings ( self . _env , int ( flag ) , self . _rule ) | Whether or not the Rule firings are being watched . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.