idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
30,500
def apply ( cls , args , run ) : try : priority = float ( args ) except ValueError : raise ValueError ( "The PRIORITY argument must be a number! " "(but was '{}')" . format ( args ) ) run . meta_info [ 'priority' ] = priority
Add priority info for this run .
30,501
def capture ( self , function = None , prefix = None ) : if function in self . captured_functions : return function captured_function = create_captured_function ( function , prefix = prefix ) self . captured_functions . append ( captured_function ) return captured_function
Decorator to turn a function into a captured function .
30,502
def pre_run_hook ( self , func , prefix = None ) : cf = self . capture ( func , prefix = prefix ) self . pre_run_hooks . append ( cf ) return cf
Decorator to add a pre - run hook to this ingredient .
30,503
def post_run_hook ( self , func , prefix = None ) : cf = self . capture ( func , prefix = prefix ) self . post_run_hooks . append ( cf ) return cf
Decorator to add a post - run hook to this ingredient .
30,504
def command ( self , function = None , prefix = None , unobserved = False ) : captured_f = self . capture ( function , prefix = prefix ) captured_f . unobserved = unobserved self . commands [ function . __name__ ] = captured_f return captured_f
Decorator to define a new command for this Ingredient or Experiment .
30,505
def config ( self , function ) : self . configurations . append ( ConfigScope ( function ) ) return self . configurations [ - 1 ]
Decorator to add a function to the configuration of the Experiment .
30,506
def named_config ( self , func ) : config_scope = ConfigScope ( func ) self . _add_named_config ( func . __name__ , config_scope ) return config_scope
Decorator to turn a function into a named configuration .
30,507
def config_hook ( self , func ) : argspec = inspect . getargspec ( func ) args = [ 'config' , 'command_name' , 'logger' ] if not ( argspec . args == args and argspec . varargs is None and argspec . keywords is None and argspec . defaults is None ) : raise ValueError ( 'Wrong signature for config_hook. Expected: ' '(con...
Decorator to add a config hook to this ingredient .
30,508
def add_package_dependency ( self , package_name , version ) : if not PEP440_VERSION_PATTERN . match ( version ) : raise ValueError ( 'Invalid Version: "{}"' . format ( version ) ) self . dependencies . add ( PackageDependency ( package_name , version ) )
Add a package to the list of dependencies .
30,509
def _gather ( self , func ) : for ingredient , _ in self . traverse_ingredients ( ) : for item in func ( ingredient ) : yield item
Function needed and used by gathering functions through the decorator gather_from_ingredients in Ingredient . Don t use this function by itself outside of the decorator!
30,510
def gather_commands ( self , ingredient ) : for command_name , command in ingredient . commands . items ( ) : yield join_paths ( ingredient . path , command_name ) , command
Collect all commands from this ingredient and its sub - ingredients .
30,511
def gather_named_configs ( self , ingredient ) : for config_name , config in ingredient . named_configs . items ( ) : yield join_paths ( ingredient . path , config_name ) , config
Collect all named configs from this ingredient and its sub - ingredients .
30,512
def get_experiment_info ( self ) : dependencies = set ( ) sources = set ( ) for ing , _ in self . traverse_ingredients ( ) : dependencies |= ing . dependencies sources |= ing . sources for dep in dependencies : dep . fill_missing_version ( ) mainfile = ( self . mainfile . to_json ( self . base_dir ) [ 0 ] if self . mai...
Get a dictionary with information about this experiment .
30,513
def traverse_ingredients ( self ) : if self . _is_traversing : raise CircularDependencyError ( ingredients = [ self ] ) else : self . _is_traversing = True yield self , 0 with CircularDependencyError . track ( self ) : for ingredient in self . ingredients : for ingred , depth in ingredient . traverse_ingredients ( ) : ...
Recursively traverse this ingredient and its sub - ingredients .
30,514
def path_from_row_pks ( row , pks , use_rowid , quote = True ) : if use_rowid : bits = [ row [ 'rowid' ] ] else : bits = [ row [ pk ] [ "value" ] if isinstance ( row [ pk ] , dict ) else row [ pk ] for pk in pks ] if quote : bits = [ urllib . parse . quote_plus ( str ( bit ) ) for bit in bits ] else : bits = [ str ( bi...
Generate an optionally URL - quoted unique identifier for a row from its primary keys .
30,515
def detect_primary_keys ( conn , table ) : " Figure out primary keys for a table. " table_info_rows = [ row for row in conn . execute ( 'PRAGMA table_info("{}")' . format ( table ) ) . fetchall ( ) if row [ - 1 ] ] table_info_rows . sort ( key = lambda row : row [ - 1 ] ) return [ str ( r [ 1 ] ) for r in table_info_ro...
Figure out primary keys for a table .
30,516
def detect_fts ( conn , table ) : "Detect if table has a corresponding FTS virtual table and return it" rows = conn . execute ( detect_fts_sql ( table ) ) . fetchall ( ) if len ( rows ) == 0 : return None else : return rows [ 0 ] [ 0 ]
Detect if table has a corresponding FTS virtual table and return it
30,517
def metadata ( self , key = None , database = None , table = None , fallback = True ) : assert not ( database is None and table is not None ) , "Cannot call metadata() with table= specified but not database=" databases = self . _metadata . get ( "databases" ) or { } search_list = [ ] if database is not None : search_li...
Looks up metadata cascading backwards from specified level . Returns None if metadata value is not found .
30,518
def inspect ( self ) : " Inspect the database and return a dictionary of table metadata " if self . _inspect : return self . _inspect self . _inspect = { } for filename in self . files : if filename is MEMORY : self . _inspect [ ":memory:" ] = { "hash" : "000" , "file" : ":memory:" , "size" : 0 , "views" : { } , "table...
Inspect the database and return a dictionary of table metadata
30,519
def table_metadata ( self , database , table ) : "Fetch table-specific metadata." return ( self . metadata ( "databases" ) or { } ) . get ( database , { } ) . get ( "tables" , { } ) . get ( table , { } )
Fetch table - specific metadata .
30,520
async def execute ( self , db_name , sql , params = None , truncate = False , custom_time_limit = None , page_size = None , ) : page_size = page_size or self . page_size def sql_operation_in_thread ( conn ) : time_limit_ms = self . sql_time_limit_ms if custom_time_limit and custom_time_limit < time_limit_ms : time_limi...
Executes sql against db_name in a thread
30,521
def inspect_hash ( path ) : " Calculate the hash of a database, efficiently. " m = hashlib . sha256 ( ) with path . open ( "rb" ) as fp : while True : data = fp . read ( HASH_BLOCK_SIZE ) if not data : break m . update ( data ) return m . hexdigest ( )
Calculate the hash of a database efficiently .
30,522
def inspect_tables ( conn , database_metadata ) : " List tables and their row counts, excluding uninteresting tables. " tables = { } table_names = [ r [ "name" ] for r in conn . execute ( 'select * from sqlite_master where type="table"' ) ] for table in table_names : table_metadata = database_metadata . get ( "tables" ...
List tables and their row counts excluding uninteresting tables .
30,523
def convert_unit ( self , column , value ) : "If the user has provided a unit in the query, convert it into the column unit, if present." if column not in self . units : return value value = self . ureg ( value ) if isinstance ( value , numbers . Number ) : return value column_unit = self . ureg ( self . units [ column...
If the user has provided a unit in the query convert it into the column unit if present .
30,524
def skeleton ( files , metadata , sqlite_extensions ) : "Generate a skeleton metadata.json file for specified SQLite databases" if os . path . exists ( metadata ) : click . secho ( "File {} already exists, will not over-write" . format ( metadata ) , bg = "red" , fg = "white" , bold = True , err = True , ) sys . exit (...
Generate a skeleton metadata . json file for specified SQLite databases
30,525
def plugins ( all , plugins_dir ) : "List currently available plugins" app = Datasette ( [ ] , plugins_dir = plugins_dir ) click . echo ( json . dumps ( app . plugins ( all ) , indent = 4 ) )
List currently available plugins
30,526
def package ( files , tag , metadata , extra_options , branch , template_dir , plugins_dir , static , install , spatialite , version_note , ** extra_metadata ) : "Package specified SQLite files into a new datasette Docker container" if not shutil . which ( "docker" ) : click . secho ( ' The package command requires "do...
Package specified SQLite files into a new datasette Docker container
30,527
def serve ( files , immutable , host , port , debug , reload , cors , sqlite_extensions , inspect_file , metadata , template_dir , plugins_dir , static , memory , config , version_note , help_config , ) : if help_config : formatter = formatting . HelpFormatter ( ) with formatter . section ( "Config options" ) : formatt...
Serve up specified SQLite database files with a web UI
30,528
def bar ( df , figsize = ( 24 , 10 ) , fontsize = 16 , labels = None , log = False , color = 'dimgray' , inline = False , filter = None , n = 0 , p = 0 , sort = None ) : nullity_counts = len ( df ) - df . isnull ( ) . sum ( ) df = nullity_filter ( df , filter = filter , n = n , p = p ) df = nullity_sort ( df , sort = s...
A bar chart visualization of the nullity of the given DataFrame .
30,529
def heatmap ( df , inline = False , filter = None , n = 0 , p = 0 , sort = None , figsize = ( 20 , 12 ) , fontsize = 16 , labels = True , cmap = 'RdBu' , vmin = - 1 , vmax = 1 , cbar = True ) : df = nullity_filter ( df , filter = filter , n = n , p = p ) df = nullity_sort ( df , sort = sort ) plt . figure ( figsize = f...
Presents a seaborn heatmap visualization of nullity correlation in the given DataFrame . Note that this visualization has no special support for large datasets . For those try the dendrogram instead .
30,530
def dendrogram ( df , method = 'average' , filter = None , n = 0 , p = 0 , sort = None , orientation = None , figsize = None , fontsize = 16 , inline = False ) : if not figsize : if len ( df . columns ) <= 50 or orientation == 'top' or orientation == 'bottom' : figsize = ( 25 , 10 ) else : figsize = ( 25 , ( 25 + len (...
Fits a scipy hierarchical clustering algorithm to the given DataFrame s variables and visualizes the results as a scipy dendrogram . The default vertical display will fit up to 50 columns . If more than 50 columns are specified and orientation is left unspecified the dendrogram will automatically swap to a horizontal d...
30,531
def nullity_sort ( df , sort = None ) : if sort == 'ascending' : return df . iloc [ np . argsort ( df . count ( axis = 'columns' ) . values ) , : ] elif sort == 'descending' : return df . iloc [ np . flipud ( np . argsort ( df . count ( axis = 'columns' ) . values ) ) , : ] else : return df
Sorts a DataFrame according to its nullity in either ascending or descending order .
30,532
def from_service_account_file ( cls , filename , * args , ** kwargs ) : credentials = service_account . Credentials . from_service_account_file ( filename ) kwargs [ 'credentials' ] = credentials return cls ( * args , ** kwargs )
Creates an instance of this client using the provided credentials file .
30,533
def session_entity_type_path ( cls , project , session , entity_type ) : return google . api_core . path_template . expand ( 'projects/{project}/agent/sessions/{session}/entityTypes/{entity_type}' , project = project , session = session , entity_type = entity_type , )
Return a fully - qualified session_entity_type string .
30,534
def create_session_entity_type ( self , parent , session_entity_type , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'create_session_entity_type' not in self . _inner_api_calls : self . _inner_api_calls [ 'create_session_enti...
Creates a session entity type .
30,535
def update_session_entity_type ( self , session_entity_type , update_mask = None , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'update_session_entity_type' not in self . _inner_api_calls : self . _inner_api_calls [ 'update_...
Updates the specified session entity type .
30,536
def delete_session_entity_type ( self , name , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'delete_session_entity_type' not in self . _inner_api_calls : self . _inner_api_calls [ 'delete_session_entity_type' ] = google . ap...
Deletes the specified session entity type .
30,537
def list_knowledge_bases ( project_id ) : import dialogflow_v2beta1 as dialogflow client = dialogflow . KnowledgeBasesClient ( ) project_path = client . project_path ( project_id ) print ( 'Knowledge Bases for: {}' . format ( project_id ) ) for knowledge_base in client . list_knowledge_bases ( project_path ) : print ( ...
Lists the Knowledge bases belonging to a project .
30,538
def create_knowledge_base ( project_id , display_name ) : import dialogflow_v2beta1 as dialogflow client = dialogflow . KnowledgeBasesClient ( ) project_path = client . project_path ( project_id ) knowledge_base = dialogflow . types . KnowledgeBase ( display_name = display_name ) response = client . create_knowledge_ba...
Creates a Knowledge base .
30,539
def get_knowledge_base ( project_id , knowledge_base_id ) : import dialogflow_v2beta1 as dialogflow client = dialogflow . KnowledgeBasesClient ( ) knowledge_base_path = client . knowledge_base_path ( project_id , knowledge_base_id ) response = client . get_knowledge_base ( knowledge_base_path ) print ( 'Got Knowledge B...
Gets a specific Knowledge base .
30,540
def delete_knowledge_base ( project_id , knowledge_base_id ) : import dialogflow_v2beta1 as dialogflow client = dialogflow . KnowledgeBasesClient ( ) knowledge_base_path = client . knowledge_base_path ( project_id , knowledge_base_id ) response = client . delete_knowledge_base ( knowledge_base_path ) print ( 'Knowledge...
Deletes a specific Knowledge base .
30,541
def detect_intent_with_texttospeech_response ( project_id , session_id , texts , language_code ) : import dialogflow_v2beta1 as dialogflow session_client = dialogflow . SessionsClient ( ) session_path = session_client . session_path ( project_id , session_id ) print ( 'Session path: {}\n' . format ( session_path ) ) fo...
Returns the result of detect intent with texts as inputs and includes the response in an audio format .
30,542
def detect_intent_with_model_selection ( project_id , session_id , audio_file_path , language_code ) : import dialogflow_v2beta1 as dialogflow session_client = dialogflow . SessionsClient ( ) audio_encoding = dialogflow . enums . AudioEncoding . AUDIO_ENCODING_LINEAR_16 sample_rate_hertz = 16000 session_path = session_...
Returns the result of detect intent with model selection on an audio file as input
30,543
def knowledge_base_path ( cls , project , knowledge_base ) : return google . api_core . path_template . expand ( 'projects/{project}/knowledgeBases/{knowledge_base}' , project = project , knowledge_base = knowledge_base , )
Return a fully - qualified knowledge_base string .
30,544
def get_knowledge_base ( self , name , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'get_knowledge_base' not in self . _inner_api_calls : self . _inner_api_calls [ 'get_knowledge_base' ] = google . api_core . gapic_v1 . meth...
Retrieves the specified knowledge base .
30,545
def create_knowledge_base ( self , parent , knowledge_base , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'create_knowledge_base' not in self . _inner_api_calls : self . _inner_api_calls [ 'create_knowledge_base' ] = google ...
Creates a knowledge base .
30,546
def environment_session_path ( cls , project , environment , user , session ) : return google . api_core . path_template . expand ( 'projects/{project}/agent/environments/{environment}/users/{user}/sessions/{session}' , project = project , environment = environment , user = user , session = session , )
Return a fully - qualified environment_session string .
30,547
def environment_session_entity_type_path ( cls , project , environment , user , session , entity_type ) : return google . api_core . path_template . expand ( 'projects/{project}/agent/environments/{environment}/users/{user}/sessions/{session}/entityTypes/{entity_type}' , project = project , environment = environment , ...
Return a fully - qualified environment_session_entity_type string .
30,548
def document_path ( cls , project , knowledge_base , document ) : return google . api_core . path_template . expand ( 'projects/{project}/knowledgeBases/{knowledge_base}/documents/{document}' , project = project , knowledge_base = knowledge_base , document = document , )
Return a fully - qualified document string .
30,549
def list_documents ( self , parent , page_size = None , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'list_documents' not in self . _inner_api_calls : self . _inner_api_calls [ 'list_documents' ] = google . api_core . gapic_...
Returns the list of all documents of the knowledge base .
30,550
def delete_document ( self , name , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'delete_document' not in self . _inner_api_calls : self . _inner_api_calls [ 'delete_document' ] = google . api_core . gapic_v1 . method . wrap...
Deletes the specified document .
30,551
def context_path ( cls , project , session , context ) : return google . api_core . path_template . expand ( 'projects/{project}/agent/sessions/{session}/contexts/{context}' , project = project , session = session , context = context , )
Return a fully - qualified context string .
30,552
def get_context ( self , name , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'get_context' not in self . _inner_api_calls : self . _inner_api_calls [ 'get_context' ] = google . api_core . gapic_v1 . method . wrap_method ( se...
Retrieves the specified context .
30,553
def update_context ( self , context , update_mask = None , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'update_context' not in self . _inner_api_calls : self . _inner_api_calls [ 'update_context' ] = google . api_core . gap...
Updates the specified context .
30,554
def create_session_entity_type ( project_id , session_id , entity_values , entity_type_display_name , entity_override_mode ) : import dialogflow_v2 as dialogflow session_entity_types_client = dialogflow . SessionEntityTypesClient ( ) session_path = session_entity_types_client . session_path ( project_id , session_id ) ...
Create a session entity type with the given display name .
30,555
def delete_session_entity_type ( project_id , session_id , entity_type_display_name ) : import dialogflow_v2 as dialogflow session_entity_types_client = dialogflow . SessionEntityTypesClient ( ) session_entity_type_name = ( session_entity_types_client . session_entity_type_path ( project_id , session_id , entity_type_d...
Delete session entity type with the given entity type display name .
30,556
def create_entity_type ( project_id , display_name , kind ) : import dialogflow_v2 as dialogflow entity_types_client = dialogflow . EntityTypesClient ( ) parent = entity_types_client . project_agent_path ( project_id ) entity_type = dialogflow . types . EntityType ( display_name = display_name , kind = kind ) response ...
Create an entity type with the given display name .
30,557
def delete_entity_type ( project_id , entity_type_id ) : import dialogflow_v2 as dialogflow entity_types_client = dialogflow . EntityTypesClient ( ) entity_type_path = entity_types_client . entity_type_path ( project_id , entity_type_id ) entity_types_client . delete_entity_type ( entity_type_path )
Delete entity type with the given entity type name .
30,558
def detect_intent_texts ( project_id , session_id , texts , language_code ) : import dialogflow_v2 as dialogflow session_client = dialogflow . SessionsClient ( ) session = session_client . session_path ( project_id , session_id ) print ( 'Session path: {}\n' . format ( session ) ) for text in texts : text_input = dialo...
Returns the result of detect intent with texts as inputs .
30,559
def entity_type_path ( cls , project , entity_type ) : return google . api_core . path_template . expand ( 'projects/{project}/agent/entityTypes/{entity_type}' , project = project , entity_type = entity_type , )
Return a fully - qualified entity_type string .
30,560
def get_entity_type ( self , name , language_code = None , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'get_entity_type' not in self . _inner_api_calls : self . _inner_api_calls [ 'get_entity_type' ] = google . api_core . g...
Retrieves the specified entity type .
30,561
def create_entity_type ( self , parent , entity_type , language_code = None , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'create_entity_type' not in self . _inner_api_calls : self . _inner_api_calls [ 'create_entity_type' ...
Creates an entity type in the specified agent .
30,562
def update_entity_type ( self , entity_type , language_code = None , update_mask = None , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'update_entity_type' not in self . _inner_api_calls : self . _inner_api_calls [ 'update_e...
Updates the specified entity type .
30,563
def batch_delete_entities ( self , parent , entity_values , language_code = None , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'batch_delete_entities' not in self . _inner_api_calls : self . _inner_api_calls [ 'batch_delete...
Deletes entities in the specified entity type .
30,564
def detect_intent_knowledge ( project_id , session_id , language_code , knowledge_base_id , texts ) : import dialogflow_v2beta1 as dialogflow session_client = dialogflow . SessionsClient ( ) session_path = session_client . session_path ( project_id , session_id ) print ( 'Session path: {}\n' . format ( session_path ) )...
Returns the result of detect intent with querying Knowledge Connector .
30,565
def intent_path ( cls , project , intent ) : return google . api_core . path_template . expand ( 'projects/{project}/agent/intents/{intent}' , project = project , intent = intent , )
Return a fully - qualified intent string .
30,566
def agent_path ( cls , project , agent ) : return google . api_core . path_template . expand ( 'projects/{project}/agents/{agent}' , project = project , agent = agent , )
Return a fully - qualified agent string .
30,567
def get_intent ( self , name , language_code = None , intent_view = None , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'get_intent' not in self . _inner_api_calls : self . _inner_api_calls [ 'get_intent' ] = google . api_co...
Retrieves the specified intent .
30,568
def create_intent ( self , parent , intent , language_code = None , intent_view = None , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'create_intent' not in self . _inner_api_calls : self . _inner_api_calls [ 'create_intent'...
Creates an intent in the specified agent .
30,569
def update_intent ( self , intent , language_code , update_mask = None , intent_view = None , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'update_intent' not in self . _inner_api_calls : self . _inner_api_calls [ 'update_in...
Updates the specified intent .
30,570
def delete_intent ( self , name , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'delete_intent' not in self . _inner_api_calls : self . _inner_api_calls [ 'delete_intent' ] = google . api_core . gapic_v1 . method . wrap_metho...
Deletes the specified intent .
30,571
def batch_delete_intents ( self , parent , intents , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'batch_delete_intents' not in self . _inner_api_calls : self . _inner_api_calls [ 'batch_delete_intents' ] = google . api_core...
Deletes intents in the specified agent .
30,572
def environment_context_path ( cls , project , environment , user , session , context ) : return google . api_core . path_template . expand ( 'projects/{project}/agent/environments/{environment}/users/{user}/sessions/{session}/contexts/{context}' , project = project , environment = environment , user = user , session =...
Return a fully - qualified environment_context string .
30,573
def detect_intent_with_sentiment_analysis ( project_id , session_id , texts , language_code ) : import dialogflow_v2beta1 as dialogflow session_client = dialogflow . SessionsClient ( ) session_path = session_client . session_path ( project_id , session_id ) print ( 'Session path: {}\n' . format ( session_path ) ) for t...
Returns the result of detect intent with texts as inputs and analyzes the sentiment of the query text .
30,574
def detect_intent ( self , session , query_input , query_params = None , output_audio_config = None , input_audio = None , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'detect_intent' not in self . _inner_api_calls : self . ...
Processes a natural language query and returns structured actionable data as a result . This method is not idempotent because it may cause contexts and session entity types to be updated which in turn might affect results of future queries .
30,575
def detect_intent_stream ( project_id , session_id , audio_file_path , language_code ) : import dialogflow_v2 as dialogflow session_client = dialogflow . SessionsClient ( ) audio_encoding = dialogflow . enums . AudioEncoding . AUDIO_ENCODING_LINEAR_16 sample_rate_hertz = 16000 session_path = session_client . session_pa...
Returns the result of detect intent with streaming audio as input .
30,576
def create_intent ( project_id , display_name , training_phrases_parts , message_texts ) : import dialogflow_v2 as dialogflow intents_client = dialogflow . IntentsClient ( ) parent = intents_client . project_agent_path ( project_id ) training_phrases = [ ] for training_phrases_part in training_phrases_parts : part = di...
Create an intent of the given intent type .
30,577
def delete_intent ( project_id , intent_id ) : import dialogflow_v2 as dialogflow intents_client = dialogflow . IntentsClient ( ) intent_path = intents_client . intent_path ( project_id , intent_id ) intents_client . delete_intent ( intent_path )
Delete intent with the given intent type and intent value .
30,578
def get_agent ( self , parent , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'get_agent' not in self . _inner_api_calls : self . _inner_api_calls [ 'get_agent' ] = google . api_core . gapic_v1 . method . wrap_method ( self ....
Retrieves the specified agent .
30,579
def train_agent ( self , parent , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'train_agent' not in self . _inner_api_calls : self . _inner_api_calls [ 'train_agent' ] = google . api_core . gapic_v1 . method . wrap_method ( ...
Trains the specified agent .
30,580
def export_agent ( self , parent , agent_uri = None , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'export_agent' not in self . _inner_api_calls : self . _inner_api_calls [ 'export_agent' ] = google . api_core . gapic_v1 . m...
Exports the specified agent to a ZIP file .
30,581
def import_agent ( self , parent , agent_uri = None , agent_content = None , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None ) : if 'import_agent' not in self . _inner_api_calls : self . _inner_api_calls [ 'import_agent' ] = google . ...
Imports the specified agent from a ZIP file .
30,582
def list_documents ( project_id , knowledge_base_id ) : import dialogflow_v2beta1 as dialogflow client = dialogflow . DocumentsClient ( ) knowledge_base_path = client . knowledge_base_path ( project_id , knowledge_base_id ) print ( 'Documents for Knowledge Id: {}' . format ( knowledge_base_id ) ) for document in client...
Lists the Documents belonging to a Knowledge base .
30,583
def create_document ( project_id , knowledge_base_id , display_name , mime_type , knowledge_type , content_uri ) : import dialogflow_v2beta1 as dialogflow client = dialogflow . DocumentsClient ( ) knowledge_base_path = client . knowledge_base_path ( project_id , knowledge_base_id ) document = dialogflow . types . Docum...
Creates a Document .
30,584
def get_document ( project_id , knowledge_base_id , document_id ) : import dialogflow_v2beta1 as dialogflow client = dialogflow . DocumentsClient ( ) document_path = client . document_path ( project_id , knowledge_base_id , document_id ) response = client . get_document ( document_path ) print ( 'Got Document:' ) print...
Gets a Document .
30,585
def delete_document ( project_id , knowledge_base_id , document_id ) : import dialogflow_v2beta1 as dialogflow client = dialogflow . DocumentsClient ( ) document_path = client . document_path ( project_id , knowledge_base_id , document_id ) response = client . delete_document ( document_path ) print ( 'operation runnin...
Deletes a Document .
30,586
def create_entity ( project_id , entity_type_id , entity_value , synonyms ) : import dialogflow_v2 as dialogflow entity_types_client = dialogflow . EntityTypesClient ( ) synonyms = synonyms or [ entity_value ] entity_type_path = entity_types_client . entity_type_path ( project_id , entity_type_id ) entity = dialogflow ...
Create an entity of the given entity type .
30,587
def delete_entity ( project_id , entity_type_id , entity_value ) : import dialogflow_v2 as dialogflow entity_types_client = dialogflow . EntityTypesClient ( ) entity_type_path = entity_types_client . entity_type_path ( project_id , entity_type_id ) entity_types_client . batch_delete_entities ( entity_type_path , [ enti...
Delete entity with the given entity type and entity value .
30,588
def softmax_to_unary ( sm , GT_PROB = 1 ) : warning ( "pydensecrf.softmax_to_unary is deprecated, use unary_from_softmax instead." ) scale = None if GT_PROB == 1 else GT_PROB return unary_from_softmax ( sm , scale , clip = None )
Deprecated use unary_from_softmax instead .
30,589
def create_pairwise_gaussian ( sdims , shape ) : hcord_range = [ range ( s ) for s in shape ] mesh = np . array ( np . meshgrid ( * hcord_range , indexing = 'ij' ) , dtype = np . float32 ) for i , s in enumerate ( sdims ) : mesh [ i ] /= s return mesh . reshape ( [ len ( sdims ) , - 1 ] )
Util function that create pairwise gaussian potentials . This works for all image dimensions . For the 2D case does the same as DenseCRF2D . addPairwiseGaussian .
30,590
def create_pairwise_bilateral ( sdims , schan , img , chdim = - 1 ) : if chdim == - 1 : im_feat = img [ np . newaxis ] . astype ( np . float32 ) else : im_feat = np . rollaxis ( img , chdim ) . astype ( np . float32 ) if isinstance ( schan , Number ) : im_feat /= schan else : for i , s in enumerate ( schan ) : im_feat ...
Util function that create pairwise bilateral potentials . This works for all image dimensions . For the 2D case does the same as DenseCRF2D . addPairwiseBilateral .
30,591
def to_string ( self ) : buff = u"" for child in self . content . iter ( ) : if child . tag in [ self . qn ( 'text:p' ) , self . qn ( 'text:h' ) ] : buff += self . text_to_string ( child ) + "\n" if buff : buff = buff [ : - 1 ] return buff
Converts the document to a string .
30,592
def qn ( self , namespace ) : nsmap = { 'text' : 'urn:oasis:names:tc:opendocument:xmlns:text:1.0' , } spl = namespace . split ( ':' ) return '{{{}}}{}' . format ( nsmap [ spl [ 0 ] ] , spl [ 1 ] )
Connect tag prefix to longer namespace
30,593
def get_parser ( ) : parser = argparse . ArgumentParser ( description = ( 'Command line tool for extracting text from any document. ' ) % locals ( ) , ) parser . add_argument ( 'filename' , help = 'Filename to extract text.' , ) . completer = argcomplete . completers . FilesCompleter parser . add_argument ( '-e' , '--e...
Initialize the parser for the command line interface and bind the autocompletion functionality
30,594
def _get_available_encodings ( ) : available_encodings = set ( encodings . aliases . aliases . values ( ) ) paths = [ os . path . dirname ( encodings . __file__ ) ] for importer , modname , ispkg in pkgutil . walk_packages ( path = paths ) : available_encodings . add ( modname ) available_encodings = list ( available_e...
Get a list of the available encodings to make it easy to tab - complete the command line interface .
30,595
def extract_pdftotext ( self , filename , ** kwargs ) : if 'layout' in kwargs : args = [ 'pdftotext' , '-layout' , filename , '-' ] else : args = [ 'pdftotext' , filename , '-' ] stdout , _ = self . run ( args ) return stdout
Extract text from pdfs using the pdftotext command line utility .
30,596
def extract_pdfminer ( self , filename , ** kwargs ) : stdout , _ = self . run ( [ 'pdf2txt.py' , filename ] ) return stdout
Extract text from pdfs using pdfminer .
30,597
def convert_to_wav ( self , filename ) : temp_filename = '{0}.wav' . format ( self . temp_filename ( ) ) self . run ( [ 'sox' , '-G' , '-c' , '1' , filename , temp_filename ] ) return temp_filename
Uses sox cmdline tool to convert audio file to . wav
30,598
def _visible ( self , element ) : if element . name in self . _disallowed_names : return False elif re . match ( u'<!--.* , six . text_type ( element . extract ( ) ) ) : return False return True
Used to filter text elements that have invisible text on the page .
30,599
def _find_any_text ( self , tag ) : text = '' if tag is not None : text = six . text_type ( tag ) text = re . sub ( r'(<[^>]+>)' , '' , text ) text = re . sub ( r'\s' , ' ' , text ) text = text . strip ( ) return text
Looks for any possible text within given tag .