def get(self, id=""): """ Returns a list of atoms matching the specified criteria Uri: atoms/[id] (or) atoms?type=[type]&name=[name]&filterby=[filterby] &tvStrengthMin=[tvStrengthMin]&tvConfidenceMin=[tvConfidenceMin] &tvCountMin=[tvCountMin]&includeIncoming=[includeIncoming] &includeOutgoing=[includeOutgoing]&callback=[callback] :param id: (optional, int, to specifically request an atom by handle, can be combined with includeIncoming or includeOutgoing only; if specified, other query parameters will have no effect) Atom handle :param type: (optional) Atom type, see http://wiki.opencog.org/w/OpenCog_Atom_types :param name: (optional, string, not allowed for Link types) Atom name If neither type or name are provided, all atoms will be retrieved :param filterby: (optional, can't be combined with type or name) Allows certain predefined filters - The filter 'stirange' allows the additional parameters 'stimin' (required, int) and 'stimax' (optional, int) and returns the atoms in a given STI range - The filter 'attentionalfocus' (boolean) returns the atoms in the AttentionalFocus :param tvStrengthMin: (optional, float) Only return atoms with TruthValue strength greater than this amount :param tvConfidenceMin: (optional, float) Only return atoms with TruthValue confidence greater than this amount :param tvCountMin: (optional, float) Only return atoms with TruthValue count greater than this amount :param includeIncoming: (optional, boolean) Returns the conjunction of the set of atoms and their incoming sets :param includeOutgoing: (optional, boolean) Returns the conjunction of the set of atoms and their outgoing sets. Useful in combination with includeIncoming. :param dot: (optional, boolean) Returns the atom set represented in the DOT graph description language (See opencog/python/graph_description/README.md for details) :param callback: (optional) JavaScript callback function for JSONP support :return result: Returns a JSON representation of an atom list. Example: { 'result': { 'complete': 'true', 'skipped': 'false', 'total': 10, 'atoms': [ { 'handle': 6, 'name': '', 'type': 'InheritanceLink', 'outgoing': [2, 1], 'incoming': [], 'truthvalue': { 'type': 'simple', 'details': { 'count': '0.4000000059604645', 'confidence': '0.0004997501382604241', 'strength': '0.5' } } 'attentionvalue': { 'lti': 0, 'sti': 0, 'vlti': false } }, ... ] } } """ args = self.reqparse.parse_args() type = args.get('type') name = args.get('name') callback = args.get('callback') filter_by = args.get('filterby') sti_min = args.get('stimin') sti_max = args.get('stimax') tv_strength_min = args.get('tvStrengthMin') tv_confidence_min = args.get('tvConfidenceMin') tv_count_min = args.get('tvCountMin') include_incoming = args.get('includeIncoming') include_outgoing = args.get('includeOutgoing') dot_format = args.get('dot') if id != "": try: atom = self.atomspace[Handle(id)] atoms = [atom] except IndexError: atoms = [] # abort(404, 'Handle not found') else: # First, check if there is a valid filter type, and give it # precedence if it exists valid_filter = False if filter_by is not None: if filter_by == 'stirange': if sti_min is not None: valid_filter = True atoms = self.atomspace.get_atoms_by_av( sti_min, sti_max) else: abort( 400, 'Invalid request: stirange filter requires ' 'stimin parameter') elif filter_by == 'attentionalfocus': valid_filter = True atoms = self.atomspace.get_atoms_in_attentional_focus() # If there is not a valid filter type, proceed to select by type # or name if not valid_filter: if type is None and name is None: atoms = self.atomspace.get_atoms_by_type(types.Atom) elif name is None: atoms = self.atomspace.get_atoms_by_type( types.__dict__.get(type)) else: if type is None: type = 'Node' atoms = self.atomspace.get_atoms_by_name( t=types.__dict__.get(type), name=name) # Optionally, filter by TruthValue if tv_strength_min is not None: atoms = [ atom for atom in atoms if atom.tv.mean >= tv_strength_min ] if tv_confidence_min is not None: atoms = [ atom for atom in atoms if atom.tv.confidence >= tv_confidence_min ] if tv_count_min is not None: atoms = [ atom for atom in atoms if atom.tv.count >= tv_count_min ] # Optionally, include the incoming set if include_incoming in ['True', 'true', '1']: atoms = self.atomspace.include_incoming(atoms) # Optionally, include the outgoing set if include_outgoing in ['True', 'true', '1']: atoms = self.atomspace.include_outgoing(atoms) # The default is to return the atom set as JSON atoms. Optionally, a # DOT return format is also supported if dot_format not in ['True', 'true', '1']: atom_list = AtomListResponse(atoms) json_data = {'result': atom_list.format()} # if callback function supplied, pad the JSON data (i.e. JSONP): if callback is not None: response = str(callback) + '(' + json.dumps(json_data) + ');' return current_app.response_class( response, mimetype='application/javascript') else: return current_app.response_class(json.dumps(json_data), mimetype='application/json') else: dot_output = dot.get_dot_representation(atoms) return jsonify({'result': dot_output})
def _get(self, id=""): """ Returns a list of atoms matching the specified criteria """ args = self.reqparse.parse_args() type = args.get('type') name = args.get('name') callback = args.get('callback') filter_by = args.get('filterby') sti_min = args.get('stimin') sti_max = args.get('stimax') tv_strength_min = args.get('tvStrengthMin') tv_confidence_min = args.get('tvConfidenceMin') tv_count_min = args.get('tvCountMin') include_incoming = args.get('includeIncoming') include_outgoing = args.get('includeOutgoing') dot_format = args.get('dot') limit = args.get('limit') if id != "": try: atom = self.atom_map.get_atom(int(id)) atoms = [atom] except IndexError: atoms = [] # abort(404, 'Atom not found') else: # First, check if there is a valid filter type, and give it # precedence if it exists valid_filter = False if filter_by is not None: if filter_by == 'stirange': if sti_min is not None: valid_filter = True atoms = self.atomspace.get_atoms_by_av( sti_min, sti_max) else: abort( 400, 'Invalid request: stirange filter requires ' 'stimin parameter') elif filter_by == 'attentionalfocus': valid_filter = True atoms = self.atomspace.get_atoms_in_attentional_focus() # If there is not a valid filter type, proceed to select by type # or name if not valid_filter: if type is None and name is None: atoms = self.atomspace.get_atoms_by_type(types.Atom) elif name is None: atoms = [] for t in type: atoms = atoms + self.atomspace.get_atoms_by_type( types.__dict__.get(t)) else: if type is None: type = 'Node' atoms = get_atoms_by_name(types.__dict__.get(type), name, self.atomspace) # Optionally, filter by TruthValue if tv_strength_min is not None: atoms = [ atom for atom in atoms if atom.tv.mean >= tv_strength_min ] if tv_confidence_min is not None: atoms = [ atom for atom in atoms if atom.tv.confidence >= tv_confidence_min ] if tv_count_min is not None: atoms = [ atom for atom in atoms if atom.tv.count >= tv_count_min ] # Optionally, include the incoming set if include_incoming in ['True', 'true', '1']: atoms = self.atomspace.include_incoming(atoms) # Optionally, include the outgoing set if include_outgoing in ['True', 'true', '1']: atoms = self.atomspace.include_outgoing(atoms) # Optionally, limit number of atoms returned if limit is not None: if len(atoms) > limit: atoms = atoms[0:limit] # The default is to return the atom set as JSON atoms. Optionally, a # DOT return format is also supported if dot_format not in ['True', 'true', '1']: atom_list = AtomListResponse(atoms) # xxxxxxxxxxxx here add atoms json_data = {'result': atom_list.format()} # if callback function supplied, pad the JSON data (i.e. JSONP): if callback is not None: response = str(callback) + '(' + json.dumps(json_data) + ');' return current_app.response_class( response, mimetype='application/javascript') else: return current_app.response_class(json.dumps(json_data), mimetype='application/json') else: dot_output = dot.get_dot_representation(atoms) return jsonify({'result': dot_output})
def get(self, id=""): """ Returns a list of atoms matching the specified criteria Uri: atoms/[id] (or) atoms?type=[type]&name=[name]&filterby=[filterby] &tvStrengthMin=[tvStrengthMin]&tvConfidenceMin=[tvConfidenceMin] &tvCountMin=[tvCountMin]&includeIncoming=[includeIncoming] &includeOutgoing=[includeOutgoing]&callback=[callback] :param id: (optional, int, to specifically request an atom by handle, can be combined with includeIncoming or includeOutgoing only; if specified, other query parameters will have no effect) Atom handle :param type: (optional) Atom type, see http://wiki.opencog.org/w/OpenCog_Atom_types :param name: (optional, string, not allowed for Link types) Atom name If neither type or name are provided, all atoms will be retrieved :param filterby: (optional, can't be combined with type or name) Allows certain predefined filters - The filter 'stirange' allows the additional parameters 'stimin' (required, int) and 'stimax' (optional, int) and returns the atoms in a given STI range - The filter 'attentionalfocus' (boolean) returns the atoms in the AttentionalFocus :param tvStrengthMin: (optional, float) Only return atoms with TruthValue strength greater than this amount :param tvConfidenceMin: (optional, float) Only return atoms with TruthValue confidence greater than this amount :param tvCountMin: (optional, float) Only return atoms with TruthValue count greater than this amount :param includeIncoming: (optional, boolean) Returns the conjunction of the set of atoms and their incoming sets :param includeOutgoing: (optional, boolean) Returns the conjunction of the set of atoms and their outgoing sets. Useful in combination with includeIncoming. :param dot: (optional, boolean) Returns the atom set represented in the DOT graph description language (See opencog/python/graph_description/README.md for details) :param callback: (optional) JavaScript callback function for JSONP support :return result: Returns a JSON representation of an atom list. Example: { 'result': { 'complete': 'true', 'skipped': 'false', 'total': 10, 'atoms': [ { 'handle': 6, 'name': '', 'type': 'InheritanceLink', 'outgoing': [2, 1], 'incoming': [], 'truthvalue': { 'type': 'simple', 'details': { 'count': '0.4000000059604645', 'confidence': '0.0004997501382604241', 'strength': '0.5' } } 'attentionvalue': { 'lti': 0, 'sti': 0, 'vlti': false } }, ... ] } } """ args = self.reqparse.parse_args() type = args.get('type') name = args.get('name') callback = args.get('callback') filter_by = args.get('filterby') sti_min = args.get('stimin') sti_max = args.get('stimax') tv_strength_min = args.get('tvStrengthMin') tv_confidence_min = args.get('tvConfidenceMin') tv_count_min = args.get('tvCountMin') include_incoming = args.get('includeIncoming') include_outgoing = args.get('includeOutgoing') dot_format = args.get('dot') if id != "": try: atom = self.atomspace[Handle(id)] atoms = [atom] except IndexError: atoms = [] # abort(404, 'Handle not found') else: # First, check if there is a valid filter type, and give it # precedence if it exists valid_filter = False if filter_by is not None: if filter_by == 'stirange': if sti_min is not None: valid_filter = True atoms = self.atomspace.get_atoms_by_av(sti_min, sti_max) else: abort(400, 'Invalid request: stirange filter requires ' 'stimin parameter') elif filter_by == 'attentionalfocus': valid_filter = True atoms = self.atomspace.get_atoms_in_attentional_focus() # If there is not a valid filter type, proceed to select by type # or name if not valid_filter: if type is None and name is None: atoms = self.atomspace.get_atoms_by_type(types.Atom) elif name is None: atoms = self.atomspace.get_atoms_by_type( types.__dict__.get(type)) else: if type is None: type = 'Node' atoms = self.atomspace.get_atoms_by_name( t=types.__dict__.get(type), name=name) # Optionally, filter by TruthValue if tv_strength_min is not None: atoms = [atom for atom in atoms if atom.tv.mean >= tv_strength_min] if tv_confidence_min is not None: atoms = [atom for atom in atoms if atom.tv.confidence >= tv_confidence_min] if tv_count_min is not None: atoms = [atom for atom in atoms if atom.tv.count >= tv_count_min] # Optionally, include the incoming set if include_incoming in ['True', 'true', '1']: atoms = self.atomspace.include_incoming(atoms) # Optionally, include the outgoing set if include_outgoing in ['True', 'true', '1']: atoms = self.atomspace.include_outgoing(atoms) # The default is to return the atom set as JSON atoms. Optionally, a # DOT return format is also supported if dot_format not in ['True', 'true', '1']: atom_list = AtomListResponse(atoms) json_data = {'result': atom_list.format()} # if callback function supplied, pad the JSON data (i.e. JSONP): if callback is not None: response = str(callback) + '(' + json.dumps(json_data) + ');' return current_app.response_class( response, mimetype='application/javascript') else: return current_app.response_class( json.dumps(json_data), mimetype='application/json') else: dot_output = dot.get_dot_representation(atoms) return jsonify({'result': dot_output})
def _get(self, id=""): """ Returns a list of atoms matching the specified criteria """ args = self.reqparse.parse_args() type = args.get('type') name = args.get('name') callback = args.get('callback') filter_by = args.get('filterby') sti_min = args.get('stimin') sti_max = args.get('stimax') tv_strength_min = args.get('tvStrengthMin') tv_confidence_min = args.get('tvConfidenceMin') tv_count_min = args.get('tvCountMin') include_incoming = args.get('includeIncoming') include_outgoing = args.get('includeOutgoing') dot_format = args.get('dot') limit = args.get('limit') if id != "": try: atom = self.atomspace[Handle(id)] atoms = [atom] except IndexError: atoms = [] # abort(404, 'Handle not found') else: # First, check if there is a valid filter type, and give it # precedence if it exists valid_filter = False if filter_by is not None: if filter_by == 'stirange': if sti_min is not None: valid_filter = True atoms = self.atomspace.get_atoms_by_av(sti_min, sti_max) else: abort(400, 'Invalid request: stirange filter requires ' 'stimin parameter') elif filter_by == 'attentionalfocus': valid_filter = True atoms = self.atomspace.get_atoms_in_attentional_focus() # If there is not a valid filter type, proceed to select by type # or name if not valid_filter: if type is None and name is None: atoms = self.atomspace.get_atoms_by_type(types.Atom) elif name is None: atoms = self.atomspace.get_atoms_by_type( types.__dict__.get(type)) else: abort(400, 'Invalid request: get atoms by name no longer' ' supported') # Optionally, filter by TruthValue if tv_strength_min is not None: atoms = [atom for atom in atoms if atom.tv.mean >= tv_strength_min] if tv_confidence_min is not None: atoms = [atom for atom in atoms if atom.tv.confidence >= tv_confidence_min] if tv_count_min is not None: atoms = [atom for atom in atoms if atom.tv.count >= tv_count_min] # Optionally, include the incoming set if include_incoming in ['True', 'true', '1']: atoms = self.atomspace.include_incoming(atoms) # Optionally, include the outgoing set if include_outgoing in ['True', 'true', '1']: atoms = self.atomspace.include_outgoing(atoms) # Optionally, limit number of atoms returned if limit is not None: if len(atoms) > limit: atoms = atoms[0:limit] # The default is to return the atom set as JSON atoms. Optionally, a # DOT return format is also supported if dot_format not in ['True', 'true', '1']: atom_list = AtomListResponse(atoms) json_data = {'result': atom_list.format()} # if callback function supplied, pad the JSON data (i.e. JSONP): if callback is not None: response = str(callback) + '(' + json.dumps(json_data) + ');' return current_app.response_class( response, mimetype='application/javascript') else: return current_app.response_class( json.dumps(json_data), mimetype='application/json') else: dot_output = dot.get_dot_representation(atoms) return jsonify({'result': dot_output})
def _get(self, id=""): """ Returns a list of atoms matching the specified criteria """ args = self.reqparse.parse_args() type = args.get("type") name = args.get("name") callback = args.get("callback") filter_by = args.get("filterby") sti_min = args.get("stimin") sti_max = args.get("stimax") tv_strength_min = args.get("tvStrengthMin") tv_confidence_min = args.get("tvConfidenceMin") tv_count_min = args.get("tvCountMin") include_incoming = args.get("includeIncoming") include_outgoing = args.get("includeOutgoing") dot_format = args.get("dot") limit = args.get("limit") if id != "": try: atom = self.atomspace.get_atom_with_uuid(id) atoms = [atom] except IndexError: atoms = [] # abort(404, 'Atom not found') else: # First, check if there is a valid filter type, and give it # precedence if it exists valid_filter = False if filter_by is not None: if filter_by == "stirange": if sti_min is not None: valid_filter = True atoms = self.atomspace.get_atoms_by_av(sti_min, sti_max) else: abort(400, "Invalid request: stirange filter requires " "stimin parameter") elif filter_by == "attentionalfocus": valid_filter = True atoms = self.atomspace.get_atoms_in_attentional_focus() # If there is not a valid filter type, proceed to select by type # or name if not valid_filter: if type is None and name is None: atoms = self.atomspace.get_atoms_by_type(types.Atom) elif name is None: atoms = self.atomspace.get_atoms_by_type(types.__dict__.get(type)) else: abort(400, "Invalid request: get atoms by name no longer" " supported") # Optionally, filter by TruthValue if tv_strength_min is not None: atoms = [atom for atom in atoms if atom.tv.mean >= tv_strength_min] if tv_confidence_min is not None: atoms = [atom for atom in atoms if atom.tv.confidence >= tv_confidence_min] if tv_count_min is not None: atoms = [atom for atom in atoms if atom.tv.count >= tv_count_min] # Optionally, include the incoming set if include_incoming in ["True", "true", "1"]: atoms = self.atomspace.include_incoming(atoms) # Optionally, include the outgoing set if include_outgoing in ["True", "true", "1"]: atoms = self.atomspace.include_outgoing(atoms) # Optionally, limit number of atoms returned if limit is not None: if len(atoms) > limit: atoms = atoms[0:limit] # The default is to return the atom set as JSON atoms. Optionally, a # DOT return format is also supported if dot_format not in ["True", "true", "1"]: atom_list = AtomListResponse(atoms) json_data = {"result": atom_list.format()} # if callback function supplied, pad the JSON data (i.e. JSONP): if callback is not None: response = str(callback) + "(" + json.dumps(json_data) + ");" return current_app.response_class(response, mimetype="application/javascript") else: return current_app.response_class(json.dumps(json_data), mimetype="application/json") else: dot_output = dot.get_dot_representation(atoms) return jsonify({"result": dot_output})