id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
49,300
zebpalmer/WeatherAlerts
weatheralerts/cap.py
CapParser.get_alerts
def get_alerts(self): """ Public method that parses """ emptyfeed = "There are no active watches, warnings or advisories" alerts = [] if emptyfeed in str(self._raw_cap): pass else: main_dom = minidom.parseString(self._raw_cap) x...
python
def get_alerts(self): """ Public method that parses """ emptyfeed = "There are no active watches, warnings or advisories" alerts = [] if emptyfeed in str(self._raw_cap): pass else: main_dom = minidom.parseString(self._raw_cap) x...
[ "def", "get_alerts", "(", "self", ")", ":", "emptyfeed", "=", "\"There are no active watches, warnings or advisories\"", "alerts", "=", "[", "]", "if", "emptyfeed", "in", "str", "(", "self", ".", "_raw_cap", ")", ":", "pass", "else", ":", "main_dom", "=", "min...
Public method that parses
[ "Public", "method", "that", "parses" ]
b99513571571fa0d65b90be883bb3bc000994027
https://github.com/zebpalmer/WeatherAlerts/blob/b99513571571fa0d65b90be883bb3bc000994027/weatheralerts/cap.py#L35-L61
49,301
axil/import-ipynb
import_ipynb.py
find_notebook
def find_notebook(fullname, path=None): """find a notebook, given its fully qualified name and an optional path This turns "foo.bar" into "foo/bar.ipynb" and tries turning "Foo_Bar" into "Foo Bar" if Foo_Bar does not exist. """ name = fullname.rsplit('.', 1)[-1] if not path: path = ...
python
def find_notebook(fullname, path=None): """find a notebook, given its fully qualified name and an optional path This turns "foo.bar" into "foo/bar.ipynb" and tries turning "Foo_Bar" into "Foo Bar" if Foo_Bar does not exist. """ name = fullname.rsplit('.', 1)[-1] if not path: path = ...
[ "def", "find_notebook", "(", "fullname", ",", "path", "=", "None", ")", ":", "name", "=", "fullname", ".", "rsplit", "(", "'.'", ",", "1", ")", "[", "-", "1", "]", "if", "not", "path", ":", "path", "=", "[", "''", "]", "for", "d", "in", "path",...
find a notebook, given its fully qualified name and an optional path This turns "foo.bar" into "foo/bar.ipynb" and tries turning "Foo_Bar" into "Foo Bar" if Foo_Bar does not exist.
[ "find", "a", "notebook", "given", "its", "fully", "qualified", "name", "and", "an", "optional", "path" ]
879bfd5c89b0d3517e0e053d3134540412b05497
https://github.com/axil/import-ipynb/blob/879bfd5c89b0d3517e0e053d3134540412b05497/import_ipynb.py#L6-L23
49,302
axil/import-ipynb
import_ipynb.py
NotebookLoader.load_module
def load_module(self, fullname): """import a notebook as a module""" path = find_notebook(fullname, self.path) print ("importing Jupyter notebook from %s" % path) # load the notebook object with io.open(path, 'r', encoding='utf-8') as f: nb = read(f, 4) # ...
python
def load_module(self, fullname): """import a notebook as a module""" path = find_notebook(fullname, self.path) print ("importing Jupyter notebook from %s" % path) # load the notebook object with io.open(path, 'r', encoding='utf-8') as f: nb = read(f, 4) # ...
[ "def", "load_module", "(", "self", ",", "fullname", ")", ":", "path", "=", "find_notebook", "(", "fullname", ",", "self", ".", "path", ")", "print", "(", "\"importing Jupyter notebook from %s\"", "%", "path", ")", "# load the notebook object", "with", "io", ".",...
import a notebook as a module
[ "import", "a", "notebook", "as", "a", "module" ]
879bfd5c89b0d3517e0e053d3134540412b05497
https://github.com/axil/import-ipynb/blob/879bfd5c89b0d3517e0e053d3134540412b05497/import_ipynb.py#L31-L64
49,303
zebpalmer/WeatherAlerts
weatheralerts/geo.py
GeoDB.location_lookup
def location_lookup(self, req_location): """ returns full location given samecode or county and state. Returns False if not valid. *currently locations are a dictionary, once other geo data is added, they will move to a location class/obj* """ location = False try: ...
python
def location_lookup(self, req_location): """ returns full location given samecode or county and state. Returns False if not valid. *currently locations are a dictionary, once other geo data is added, they will move to a location class/obj* """ location = False try: ...
[ "def", "location_lookup", "(", "self", ",", "req_location", ")", ":", "location", "=", "False", "try", ":", "location", "=", "self", ".", "samecodes", "[", "req_location", "[", "'code'", "]", "]", "except", "Exception", ":", "pass", "try", ":", "location",...
returns full location given samecode or county and state. Returns False if not valid. *currently locations are a dictionary, once other geo data is added, they will move to a location class/obj*
[ "returns", "full", "location", "given", "samecode", "or", "county", "and", "state", ".", "Returns", "False", "if", "not", "valid", "." ]
b99513571571fa0d65b90be883bb3bc000994027
https://github.com/zebpalmer/WeatherAlerts/blob/b99513571571fa0d65b90be883bb3bc000994027/weatheralerts/geo.py#L20-L35
49,304
zebpalmer/WeatherAlerts
weatheralerts/geo.py
GeoDB.lookup_samecode
def lookup_samecode(self, local, state): """Given County, State return the SAME code for specified location. Return False if not found""" for location in self.samecodes: if state.lower() == self.samecodes[location]['state'].lower(): if local.lower() == self.samecodes[location...
python
def lookup_samecode(self, local, state): """Given County, State return the SAME code for specified location. Return False if not found""" for location in self.samecodes: if state.lower() == self.samecodes[location]['state'].lower(): if local.lower() == self.samecodes[location...
[ "def", "lookup_samecode", "(", "self", ",", "local", ",", "state", ")", ":", "for", "location", "in", "self", ".", "samecodes", ":", "if", "state", ".", "lower", "(", ")", "==", "self", ".", "samecodes", "[", "location", "]", "[", "'state'", "]", "."...
Given County, State return the SAME code for specified location. Return False if not found
[ "Given", "County", "State", "return", "the", "SAME", "code", "for", "specified", "location", ".", "Return", "False", "if", "not", "found" ]
b99513571571fa0d65b90be883bb3bc000994027
https://github.com/zebpalmer/WeatherAlerts/blob/b99513571571fa0d65b90be883bb3bc000994027/weatheralerts/geo.py#L37-L43
49,305
zebpalmer/WeatherAlerts
weatheralerts/geo.py
GeoDB.getfeedscope
def getfeedscope(self, geocodes): """Given multiple SAME codes, determine if they are all in one state. If so, it returns that state. Otherwise return 'US'. This is used to determine which NWS feed needs to be parsed to get all alerts for the requested SAME codes""" states = self._...
python
def getfeedscope(self, geocodes): """Given multiple SAME codes, determine if they are all in one state. If so, it returns that state. Otherwise return 'US'. This is used to determine which NWS feed needs to be parsed to get all alerts for the requested SAME codes""" states = self._...
[ "def", "getfeedscope", "(", "self", ",", "geocodes", ")", ":", "states", "=", "self", ".", "_get_states_from_samecodes", "(", "geocodes", ")", "if", "len", "(", "states", ")", ">=", "2", ":", "return", "'US'", "else", ":", "return", "states", "[", "0", ...
Given multiple SAME codes, determine if they are all in one state. If so, it returns that state. Otherwise return 'US'. This is used to determine which NWS feed needs to be parsed to get all alerts for the requested SAME codes
[ "Given", "multiple", "SAME", "codes", "determine", "if", "they", "are", "all", "in", "one", "state", ".", "If", "so", "it", "returns", "that", "state", ".", "Otherwise", "return", "US", ".", "This", "is", "used", "to", "determine", "which", "NWS", "feed"...
b99513571571fa0d65b90be883bb3bc000994027
https://github.com/zebpalmer/WeatherAlerts/blob/b99513571571fa0d65b90be883bb3bc000994027/weatheralerts/geo.py#L55-L63
49,306
zebpalmer/WeatherAlerts
weatheralerts/geo.py
GeoDB._get_states_from_samecodes
def _get_states_from_samecodes(self, geocodes): """Returns all states for a given list of SAME codes *Shouldn't be used to determine feed scope, please use getfeedscope()* """ states = [] for code in geocodes: if not isinstance(geocodes, list): raise ...
python
def _get_states_from_samecodes(self, geocodes): """Returns all states for a given list of SAME codes *Shouldn't be used to determine feed scope, please use getfeedscope()* """ states = [] for code in geocodes: if not isinstance(geocodes, list): raise ...
[ "def", "_get_states_from_samecodes", "(", "self", ",", "geocodes", ")", ":", "states", "=", "[", "]", "for", "code", "in", "geocodes", ":", "if", "not", "isinstance", "(", "geocodes", ",", "list", ")", ":", "raise", "Exception", "(", "\"specified geocodes mu...
Returns all states for a given list of SAME codes *Shouldn't be used to determine feed scope, please use getfeedscope()*
[ "Returns", "all", "states", "for", "a", "given", "list", "of", "SAME", "codes" ]
b99513571571fa0d65b90be883bb3bc000994027
https://github.com/zebpalmer/WeatherAlerts/blob/b99513571571fa0d65b90be883bb3bc000994027/weatheralerts/geo.py#L65-L81
49,307
zebpalmer/WeatherAlerts
weatheralerts/geo.py
SameCodes._load_same_codes
def _load_same_codes(self, refresh=False): """Loads the Same Codes into this object""" if refresh is True: self._get_same_codes() else: self._cached_same_codes()
python
def _load_same_codes(self, refresh=False): """Loads the Same Codes into this object""" if refresh is True: self._get_same_codes() else: self._cached_same_codes()
[ "def", "_load_same_codes", "(", "self", ",", "refresh", "=", "False", ")", ":", "if", "refresh", "is", "True", ":", "self", ".", "_get_same_codes", "(", ")", "else", ":", "self", ".", "_cached_same_codes", "(", ")" ]
Loads the Same Codes into this object
[ "Loads", "the", "Same", "Codes", "into", "this", "object" ]
b99513571571fa0d65b90be883bb3bc000994027
https://github.com/zebpalmer/WeatherAlerts/blob/b99513571571fa0d65b90be883bb3bc000994027/weatheralerts/geo.py#L106-L111
49,308
zebpalmer/WeatherAlerts
weatheralerts/geo.py
SameCodes._get_same_codes
def _get_same_codes(self): """get SAME codes, load into a dict and cache""" same = {} url = '''http://www.nws.noaa.gov/nwr/data/SameCode.txt''' # pylint: disable=E1103 raw = requests.get(url).content.decode('utf-8') # py3 compatibility for row in raw.split('\n'): ...
python
def _get_same_codes(self): """get SAME codes, load into a dict and cache""" same = {} url = '''http://www.nws.noaa.gov/nwr/data/SameCode.txt''' # pylint: disable=E1103 raw = requests.get(url).content.decode('utf-8') # py3 compatibility for row in raw.split('\n'): ...
[ "def", "_get_same_codes", "(", "self", ")", ":", "same", "=", "{", "}", "url", "=", "'''http://www.nws.noaa.gov/nwr/data/SameCode.txt'''", "# pylint: disable=E1103", "raw", "=", "requests", ".", "get", "(", "url", ")", ".", "content", ".", "decode", "(", "'utf-8...
get SAME codes, load into a dict and cache
[ "get", "SAME", "codes", "load", "into", "a", "dict", "and", "cache" ]
b99513571571fa0d65b90be883bb3bc000994027
https://github.com/zebpalmer/WeatherAlerts/blob/b99513571571fa0d65b90be883bb3bc000994027/weatheralerts/geo.py#L113-L132
49,309
zebpalmer/WeatherAlerts
weatheralerts/geo.py
SameCodes._cached_same_codes
def _cached_same_codes(self): """If a cached copy is available, return it""" cache_file = self._same_cache_file if os.path.exists(cache_file): maxage = datetime.now() - timedelta(minutes=4320) file_ts = datetime.fromtimestamp(os.stat(cache_file).st_mtime) if f...
python
def _cached_same_codes(self): """If a cached copy is available, return it""" cache_file = self._same_cache_file if os.path.exists(cache_file): maxage = datetime.now() - timedelta(minutes=4320) file_ts = datetime.fromtimestamp(os.stat(cache_file).st_mtime) if f...
[ "def", "_cached_same_codes", "(", "self", ")", ":", "cache_file", "=", "self", ".", "_same_cache_file", "if", "os", ".", "path", ".", "exists", "(", "cache_file", ")", ":", "maxage", "=", "datetime", ".", "now", "(", ")", "-", "timedelta", "(", "minutes"...
If a cached copy is available, return it
[ "If", "a", "cached", "copy", "is", "available", "return", "it" ]
b99513571571fa0d65b90be883bb3bc000994027
https://github.com/zebpalmer/WeatherAlerts/blob/b99513571571fa0d65b90be883bb3bc000994027/weatheralerts/geo.py#L134-L148
49,310
RIPE-NCC/ripe.atlas.sagan
ripe/atlas/sagan/traceroute.py
TracerouteResult.set_destination_ip_responded
def set_destination_ip_responded(self, last_hop): """Sets the flag if destination IP responded.""" if not self.destination_address: return for packet in last_hop.packets: if packet.origin and \ self.destination_address == packet.origin: ...
python
def set_destination_ip_responded(self, last_hop): """Sets the flag if destination IP responded.""" if not self.destination_address: return for packet in last_hop.packets: if packet.origin and \ self.destination_address == packet.origin: ...
[ "def", "set_destination_ip_responded", "(", "self", ",", "last_hop", ")", ":", "if", "not", "self", ".", "destination_address", ":", "return", "for", "packet", "in", "last_hop", ".", "packets", ":", "if", "packet", ".", "origin", "and", "self", ".", "destina...
Sets the flag if destination IP responded.
[ "Sets", "the", "flag", "if", "destination", "IP", "responded", "." ]
f0e57221cf0ba3504baddd3ea460fc955bc41cc6
https://github.com/RIPE-NCC/ripe.atlas.sagan/blob/f0e57221cf0ba3504baddd3ea460fc955bc41cc6/ripe/atlas/sagan/traceroute.py#L164-L173
49,311
RIPE-NCC/ripe.atlas.sagan
ripe/atlas/sagan/traceroute.py
TracerouteResult.set_last_hop_responded
def set_last_hop_responded(self, last_hop): """Sets the flag if last hop responded.""" for packet in last_hop.packets: if packet.rtt: self.last_hop_responded = True break
python
def set_last_hop_responded(self, last_hop): """Sets the flag if last hop responded.""" for packet in last_hop.packets: if packet.rtt: self.last_hop_responded = True break
[ "def", "set_last_hop_responded", "(", "self", ",", "last_hop", ")", ":", "for", "packet", "in", "last_hop", ".", "packets", ":", "if", "packet", ".", "rtt", ":", "self", ".", "last_hop_responded", "=", "True", "break" ]
Sets the flag if last hop responded.
[ "Sets", "the", "flag", "if", "last", "hop", "responded", "." ]
f0e57221cf0ba3504baddd3ea460fc955bc41cc6
https://github.com/RIPE-NCC/ripe.atlas.sagan/blob/f0e57221cf0ba3504baddd3ea460fc955bc41cc6/ripe/atlas/sagan/traceroute.py#L175-L180
49,312
RIPE-NCC/ripe.atlas.sagan
ripe/atlas/sagan/traceroute.py
TracerouteResult.set_is_success
def set_is_success(self, last_hop): """Sets the flag if traceroute result is successful or not.""" for packet in last_hop.packets: if packet.rtt and not packet.is_error: self.is_success = True break else: self.set_last_hop_errors(last_hop)
python
def set_is_success(self, last_hop): """Sets the flag if traceroute result is successful or not.""" for packet in last_hop.packets: if packet.rtt and not packet.is_error: self.is_success = True break else: self.set_last_hop_errors(last_hop)
[ "def", "set_is_success", "(", "self", ",", "last_hop", ")", ":", "for", "packet", "in", "last_hop", ".", "packets", ":", "if", "packet", ".", "rtt", "and", "not", "packet", ".", "is_error", ":", "self", ".", "is_success", "=", "True", "break", "else", ...
Sets the flag if traceroute result is successful or not.
[ "Sets", "the", "flag", "if", "traceroute", "result", "is", "successful", "or", "not", "." ]
f0e57221cf0ba3504baddd3ea460fc955bc41cc6
https://github.com/RIPE-NCC/ripe.atlas.sagan/blob/f0e57221cf0ba3504baddd3ea460fc955bc41cc6/ripe/atlas/sagan/traceroute.py#L182-L189
49,313
RIPE-NCC/ripe.atlas.sagan
ripe/atlas/sagan/traceroute.py
TracerouteResult.set_last_hop_errors
def set_last_hop_errors(self, last_hop): """Sets the last hop's errors.""" if last_hop.is_error: self.last_hop_errors.append(last_hop.error_message) return for packet in last_hop.packets: if packet.is_error: self.last_hop_errors.append(packet....
python
def set_last_hop_errors(self, last_hop): """Sets the last hop's errors.""" if last_hop.is_error: self.last_hop_errors.append(last_hop.error_message) return for packet in last_hop.packets: if packet.is_error: self.last_hop_errors.append(packet....
[ "def", "set_last_hop_errors", "(", "self", ",", "last_hop", ")", ":", "if", "last_hop", ".", "is_error", ":", "self", ".", "last_hop_errors", ".", "append", "(", "last_hop", ".", "error_message", ")", "return", "for", "packet", "in", "last_hop", ".", "packet...
Sets the last hop's errors.
[ "Sets", "the", "last", "hop", "s", "errors", "." ]
f0e57221cf0ba3504baddd3ea460fc955bc41cc6
https://github.com/RIPE-NCC/ripe.atlas.sagan/blob/f0e57221cf0ba3504baddd3ea460fc955bc41cc6/ripe/atlas/sagan/traceroute.py#L191-L199
49,314
RIPE-NCC/ripe.atlas.sagan
ripe/atlas/sagan/traceroute.py
TracerouteResult.ip_path
def ip_path(self): """ Returns just the IPs from the traceroute. """ r = [] for hop in self.hops: r.append([packet.origin for packet in hop.packets]) return r
python
def ip_path(self): """ Returns just the IPs from the traceroute. """ r = [] for hop in self.hops: r.append([packet.origin for packet in hop.packets]) return r
[ "def", "ip_path", "(", "self", ")", ":", "r", "=", "[", "]", "for", "hop", "in", "self", ".", "hops", ":", "r", ".", "append", "(", "[", "packet", ".", "origin", "for", "packet", "in", "hop", ".", "packets", "]", ")", "return", "r" ]
Returns just the IPs from the traceroute.
[ "Returns", "just", "the", "IPs", "from", "the", "traceroute", "." ]
f0e57221cf0ba3504baddd3ea460fc955bc41cc6
https://github.com/RIPE-NCC/ripe.atlas.sagan/blob/f0e57221cf0ba3504baddd3ea460fc955bc41cc6/ripe/atlas/sagan/traceroute.py#L206-L213
49,315
DancingQuanta/pyusbiss
usbiss/usbiss.py
USBISS.get_iss_info
def get_iss_info(self): """ Get information about the USB-ISS Querying will return three bytes; - the module ID (7), - firmware version (currently 2), - the current operating mode. """ self.write_data([self.ISS_CMD, self.ISS_VERSION]) response = s...
python
def get_iss_info(self): """ Get information about the USB-ISS Querying will return three bytes; - the module ID (7), - firmware version (currently 2), - the current operating mode. """ self.write_data([self.ISS_CMD, self.ISS_VERSION]) response = s...
[ "def", "get_iss_info", "(", "self", ")", ":", "self", ".", "write_data", "(", "[", "self", ".", "ISS_CMD", ",", "self", ".", "ISS_VERSION", "]", ")", "response", "=", "self", ".", "read_data", "(", "3", ")", "if", "len", "(", "response", ")", "==", ...
Get information about the USB-ISS Querying will return three bytes; - the module ID (7), - firmware version (currently 2), - the current operating mode.
[ "Get", "information", "about", "the", "USB", "-", "ISS" ]
fc64e123f1c97f53ad153c474d230ad38044c3cb
https://github.com/DancingQuanta/pyusbiss/blob/fc64e123f1c97f53ad153c474d230ad38044c3cb/usbiss/usbiss.py#L95-L112
49,316
DancingQuanta/pyusbiss
usbiss/usbiss.py
USBISS.get_iss_serial_no
def get_iss_serial_no(self): """ Get serial number of USB-ISS module """ self.write_data([self.ISS_CMD, self.ISS_SER_NUM]) # Return 8 bytes serial number self.iss_sn = self.read_data(8)
python
def get_iss_serial_no(self): """ Get serial number of USB-ISS module """ self.write_data([self.ISS_CMD, self.ISS_SER_NUM]) # Return 8 bytes serial number self.iss_sn = self.read_data(8)
[ "def", "get_iss_serial_no", "(", "self", ")", ":", "self", ".", "write_data", "(", "[", "self", ".", "ISS_CMD", ",", "self", ".", "ISS_SER_NUM", "]", ")", "# Return 8 bytes serial number", "self", ".", "iss_sn", "=", "self", ".", "read_data", "(", "8", ")"...
Get serial number of USB-ISS module
[ "Get", "serial", "number", "of", "USB", "-", "ISS", "module" ]
fc64e123f1c97f53ad153c474d230ad38044c3cb
https://github.com/DancingQuanta/pyusbiss/blob/fc64e123f1c97f53ad153c474d230ad38044c3cb/usbiss/usbiss.py#L114-L119
49,317
DancingQuanta/pyusbiss
usbiss/usbiss.py
USBISS.mode
def mode(self, set_bytes): """Set the operating protocol of the USB-ISS with additional parameters for the protocol """ self._mode = set_bytes data = [self.ISS_CMD, self.ISS_SET_MODE] + set_bytes self.write_data(data) response = self.read_data(2) if respo...
python
def mode(self, set_bytes): """Set the operating protocol of the USB-ISS with additional parameters for the protocol """ self._mode = set_bytes data = [self.ISS_CMD, self.ISS_SET_MODE] + set_bytes self.write_data(data) response = self.read_data(2) if respo...
[ "def", "mode", "(", "self", ",", "set_bytes", ")", ":", "self", ".", "_mode", "=", "set_bytes", "data", "=", "[", "self", ".", "ISS_CMD", ",", "self", ".", "ISS_SET_MODE", "]", "+", "set_bytes", "self", ".", "write_data", "(", "data", ")", "response", ...
Set the operating protocol of the USB-ISS with additional parameters for the protocol
[ "Set", "the", "operating", "protocol", "of", "the", "USB", "-", "ISS", "with", "additional", "parameters", "for", "the", "protocol" ]
fc64e123f1c97f53ad153c474d230ad38044c3cb
https://github.com/DancingQuanta/pyusbiss/blob/fc64e123f1c97f53ad153c474d230ad38044c3cb/usbiss/usbiss.py#L134-L151
49,318
blakev/python-syncthing
syncthing/__init__.py
keys_to_datetime
def keys_to_datetime(obj, *keys): """ Converts all the keys in an object to DateTime instances. Args: obj (dict): the JSON-like ``dict`` object to modify inplace. keys (str): keys of the object being converted into DateTime instances. Returns: di...
python
def keys_to_datetime(obj, *keys): """ Converts all the keys in an object to DateTime instances. Args: obj (dict): the JSON-like ``dict`` object to modify inplace. keys (str): keys of the object being converted into DateTime instances. Returns: di...
[ "def", "keys_to_datetime", "(", "obj", ",", "*", "keys", ")", ":", "if", "not", "keys", ":", "return", "obj", "for", "k", "in", "keys", ":", "if", "k", "not", "in", "obj", ":", "continue", "v", "=", "obj", "[", "k", "]", "if", "not", "isinstance"...
Converts all the keys in an object to DateTime instances. Args: obj (dict): the JSON-like ``dict`` object to modify inplace. keys (str): keys of the object being converted into DateTime instances. Returns: dict: ``obj`` inplace. >>> keys_to_...
[ "Converts", "all", "the", "keys", "in", "an", "object", "to", "DateTime", "instances", "." ]
a7f4930f86f7543cd96990277945467896fb523d
https://github.com/blakev/python-syncthing/blob/a7f4930f86f7543cd96990277945467896fb523d/syncthing/__init__.py#L67-L103
49,319
blakev/python-syncthing
syncthing/__init__.py
System.browse
def browse(self, path=None): """ Returns a list of directories matching the path given. Args: path (str): glob pattern. Returns: List[str] """ params = None if path: assert isinstance(path, string_types) params = {'current...
python
def browse(self, path=None): """ Returns a list of directories matching the path given. Args: path (str): glob pattern. Returns: List[str] """ params = None if path: assert isinstance(path, string_types) params = {'current...
[ "def", "browse", "(", "self", ",", "path", "=", "None", ")", ":", "params", "=", "None", "if", "path", ":", "assert", "isinstance", "(", "path", ",", "string_types", ")", "params", "=", "{", "'current'", ":", "path", "}", "return", "self", ".", "get"...
Returns a list of directories matching the path given. Args: path (str): glob pattern. Returns: List[str]
[ "Returns", "a", "list", "of", "directories", "matching", "the", "path", "given", "." ]
a7f4930f86f7543cd96990277945467896fb523d
https://github.com/blakev/python-syncthing/blob/a7f4930f86f7543cd96990277945467896fb523d/syncthing/__init__.py#L243-L256
49,320
blakev/python-syncthing
syncthing/__init__.py
System.config_insync
def config_insync(self): """ Returns whether the config is in sync, i.e. whether the running configuration is the same as that on disk. Returns: bool """ status = self.get('config/insync').get('configInSync', False) if status is None: ...
python
def config_insync(self): """ Returns whether the config is in sync, i.e. whether the running configuration is the same as that on disk. Returns: bool """ status = self.get('config/insync').get('configInSync', False) if status is None: ...
[ "def", "config_insync", "(", "self", ")", ":", "status", "=", "self", ".", "get", "(", "'config/insync'", ")", ".", "get", "(", "'configInSync'", ",", "False", ")", "if", "status", "is", "None", ":", "status", "=", "False", "return", "status" ]
Returns whether the config is in sync, i.e. whether the running configuration is the same as that on disk. Returns: bool
[ "Returns", "whether", "the", "config", "is", "in", "sync", "i", ".", "e", ".", "whether", "the", "running", "configuration", "is", "the", "same", "as", "that", "on", "disk", "." ]
a7f4930f86f7543cd96990277945467896fb523d
https://github.com/blakev/python-syncthing/blob/a7f4930f86f7543cd96990277945467896fb523d/syncthing/__init__.py#L288-L298
49,321
blakev/python-syncthing
syncthing/__init__.py
System.errors
def errors(self): """ Returns the list of recent errors. Returns: list: of :obj:`.ErrorEvent` tuples. """ ret_errs = list() errors = self.get('error').get('errors', None) or list() assert isinstance(errors, list) for err in errors: ...
python
def errors(self): """ Returns the list of recent errors. Returns: list: of :obj:`.ErrorEvent` tuples. """ ret_errs = list() errors = self.get('error').get('errors', None) or list() assert isinstance(errors, list) for err in errors: ...
[ "def", "errors", "(", "self", ")", ":", "ret_errs", "=", "list", "(", ")", "errors", "=", "self", ".", "get", "(", "'error'", ")", ".", "get", "(", "'errors'", ",", "None", ")", "or", "list", "(", ")", "assert", "isinstance", "(", "errors", ",", ...
Returns the list of recent errors. Returns: list: of :obj:`.ErrorEvent` tuples.
[ "Returns", "the", "list", "of", "recent", "errors", "." ]
a7f4930f86f7543cd96990277945467896fb523d
https://github.com/blakev/python-syncthing/blob/a7f4930f86f7543cd96990277945467896fb523d/syncthing/__init__.py#L399-L413
49,322
blakev/python-syncthing
syncthing/__init__.py
System.show_error
def show_error(self, message): """ Send an error message to the active client. The new error will be displayed on any active GUI clients. Args: message (str): Plain-text message to display. Returns: None >>> s = _syncthing() ...
python
def show_error(self, message): """ Send an error message to the active client. The new error will be displayed on any active GUI clients. Args: message (str): Plain-text message to display. Returns: None >>> s = _syncthing() ...
[ "def", "show_error", "(", "self", ",", "message", ")", ":", "assert", "isinstance", "(", "message", ",", "string_types", ")", "self", ".", "post", "(", "'error'", ",", "data", "=", "message", ")" ]
Send an error message to the active client. The new error will be displayed on any active GUI clients. Args: message (str): Plain-text message to display. Returns: None >>> s = _syncthing() >>> s.system.show_error('my error m...
[ "Send", "an", "error", "message", "to", "the", "active", "client", ".", "The", "new", "error", "will", "be", "displayed", "on", "any", "active", "GUI", "clients", "." ]
a7f4930f86f7543cd96990277945467896fb523d
https://github.com/blakev/python-syncthing/blob/a7f4930f86f7543cd96990277945467896fb523d/syncthing/__init__.py#L415-L435
49,323
blakev/python-syncthing
syncthing/__init__.py
System.pause
def pause(self, device): """ Pause the given device. Args: device (str): Device ID. Returns: dict: with keys ``success`` and ``error``. """ resp = self.post('pause', params={'device': device}, return_response=True...
python
def pause(self, device): """ Pause the given device. Args: device (str): Device ID. Returns: dict: with keys ``success`` and ``error``. """ resp = self.post('pause', params={'device': device}, return_response=True...
[ "def", "pause", "(", "self", ",", "device", ")", ":", "resp", "=", "self", ".", "post", "(", "'pause'", ",", "params", "=", "{", "'device'", ":", "device", "}", ",", "return_response", "=", "True", ")", "error", "=", "resp", ".", "text", "if", "not...
Pause the given device. Args: device (str): Device ID. Returns: dict: with keys ``success`` and ``error``.
[ "Pause", "the", "given", "device", "." ]
a7f4930f86f7543cd96990277945467896fb523d
https://github.com/blakev/python-syncthing/blob/a7f4930f86f7543cd96990277945467896fb523d/syncthing/__init__.py#L445-L460
49,324
blakev/python-syncthing
syncthing/__init__.py
System.reset_folder
def reset_folder(self, folder): """ Erase the database index from a given folder and restart Syncthing. Args: folder (str): Folder ID. Returns: None """ warnings.warn('This is a destructive action that cannot be undone.') self.pos...
python
def reset_folder(self, folder): """ Erase the database index from a given folder and restart Syncthing. Args: folder (str): Folder ID. Returns: None """ warnings.warn('This is a destructive action that cannot be undone.') self.pos...
[ "def", "reset_folder", "(", "self", ",", "folder", ")", ":", "warnings", ".", "warn", "(", "'This is a destructive action that cannot be undone.'", ")", "self", ".", "post", "(", "'reset'", ",", "data", "=", "{", "}", ",", "params", "=", "{", "'folder'", ":"...
Erase the database index from a given folder and restart Syncthing. Args: folder (str): Folder ID. Returns: None
[ "Erase", "the", "database", "index", "from", "a", "given", "folder", "and", "restart", "Syncthing", "." ]
a7f4930f86f7543cd96990277945467896fb523d
https://github.com/blakev/python-syncthing/blob/a7f4930f86f7543cd96990277945467896fb523d/syncthing/__init__.py#L486-L496
49,325
blakev/python-syncthing
syncthing/__init__.py
Database.browse
def browse(self, folder, levels=None, prefix=None): """ Returns the directory tree of the global model. Directories are always JSON objects (map/dictionary), and files are always arrays of modification time and size. The first integer is the files modification time, and the ...
python
def browse(self, folder, levels=None, prefix=None): """ Returns the directory tree of the global model. Directories are always JSON objects (map/dictionary), and files are always arrays of modification time and size. The first integer is the files modification time, and the ...
[ "def", "browse", "(", "self", ",", "folder", ",", "levels", "=", "None", ",", "prefix", "=", "None", ")", ":", "assert", "isinstance", "(", "levels", ",", "int", ")", "or", "levels", "is", "None", "assert", "isinstance", "(", "prefix", ",", "string_typ...
Returns the directory tree of the global model. Directories are always JSON objects (map/dictionary), and files are always arrays of modification time and size. The first integer is the files modification time, and the second integer is the file size. Args: ...
[ "Returns", "the", "directory", "tree", "of", "the", "global", "model", "." ]
a7f4930f86f7543cd96990277945467896fb523d
https://github.com/blakev/python-syncthing/blob/a7f4930f86f7543cd96990277945467896fb523d/syncthing/__init__.py#L581-L603
49,326
blakev/python-syncthing
syncthing/__init__.py
Database.set_ignores
def set_ignores(self, folder, *patterns): """ Applies ``patterns`` to ``folder``'s ``.stignore`` file. Args: folder (str): patterns (str): Returns: dict """ if not patterns: return {} data = {'ignore': ...
python
def set_ignores(self, folder, *patterns): """ Applies ``patterns`` to ``folder``'s ``.stignore`` file. Args: folder (str): patterns (str): Returns: dict """ if not patterns: return {} data = {'ignore': ...
[ "def", "set_ignores", "(", "self", ",", "folder", ",", "*", "patterns", ")", ":", "if", "not", "patterns", ":", "return", "{", "}", "data", "=", "{", "'ignore'", ":", "list", "(", "patterns", ")", "}", "return", "self", ".", "post", "(", "'ignores'",...
Applies ``patterns`` to ``folder``'s ``.stignore`` file. Args: folder (str): patterns (str): Returns: dict
[ "Applies", "patterns", "to", "folder", "s", ".", "stignore", "file", "." ]
a7f4930f86f7543cd96990277945467896fb523d
https://github.com/blakev/python-syncthing/blob/a7f4930f86f7543cd96990277945467896fb523d/syncthing/__init__.py#L655-L668
49,327
blakev/python-syncthing
syncthing/__init__.py
Database.need
def need(self, folder, page=None, perpage=None): """ Returns lists of files which are needed by this device in order for it to become in sync. Args: folder (str): page (int): If defined applies pagination accross the collection of results....
python
def need(self, folder, page=None, perpage=None): """ Returns lists of files which are needed by this device in order for it to become in sync. Args: folder (str): page (int): If defined applies pagination accross the collection of results....
[ "def", "need", "(", "self", ",", "folder", ",", "page", "=", "None", ",", "perpage", "=", "None", ")", ":", "assert", "isinstance", "(", "page", ",", "int", ")", "or", "page", "is", "None", "assert", "isinstance", "(", "perpage", ",", "int", ")", "...
Returns lists of files which are needed by this device in order for it to become in sync. Args: folder (str): page (int): If defined applies pagination accross the collection of results. perpage (int): If defined applies pagination...
[ "Returns", "lists", "of", "files", "which", "are", "needed", "by", "this", "device", "in", "order", "for", "it", "to", "become", "in", "sync", "." ]
a7f4930f86f7543cd96990277945467896fb523d
https://github.com/blakev/python-syncthing/blob/a7f4930f86f7543cd96990277945467896fb523d/syncthing/__init__.py#L670-L688
49,328
blakev/python-syncthing
syncthing/__init__.py
Database.scan
def scan(self, folder, sub=None, next_=None): """ Request immediate rescan of a folder, or a specific path within a folder. Args: folder (str): Folder ID. sub (str): Path relative to the folder root. If sub is omitted the entire folder is ...
python
def scan(self, folder, sub=None, next_=None): """ Request immediate rescan of a folder, or a specific path within a folder. Args: folder (str): Folder ID. sub (str): Path relative to the folder root. If sub is omitted the entire folder is ...
[ "def", "scan", "(", "self", ",", "folder", ",", "sub", "=", "None", ",", "next_", "=", "None", ")", ":", "if", "not", "sub", ":", "sub", "=", "''", "assert", "isinstance", "(", "sub", ",", "string_types", ")", "assert", "isinstance", "(", "next_", ...
Request immediate rescan of a folder, or a specific path within a folder. Args: folder (str): Folder ID. sub (str): Path relative to the folder root. If sub is omitted the entire folder is scanned for changes, otherwise only th...
[ "Request", "immediate", "rescan", "of", "a", "folder", "or", "a", "specific", "path", "within", "a", "folder", "." ]
a7f4930f86f7543cd96990277945467896fb523d
https://github.com/blakev/python-syncthing/blob/a7f4930f86f7543cd96990277945467896fb523d/syncthing/__init__.py#L714-L735
49,329
blakev/python-syncthing
syncthing/__init__.py
Events._events
def _events(self, using_url, filters=None, limit=None): """ A long-polling method that queries Syncthing for events.. Args: using_url (str): REST HTTP endpoint filters (List[str]): Creates an "event group" in Syncthing to only receive events that ...
python
def _events(self, using_url, filters=None, limit=None): """ A long-polling method that queries Syncthing for events.. Args: using_url (str): REST HTTP endpoint filters (List[str]): Creates an "event group" in Syncthing to only receive events that ...
[ "def", "_events", "(", "self", ",", "using_url", ",", "filters", "=", "None", ",", "limit", "=", "None", ")", ":", "# coerce", "if", "not", "isinstance", "(", "limit", ",", "(", "int", ",", "NoneType", ")", ")", ":", "limit", "=", "None", "# coerce",...
A long-polling method that queries Syncthing for events.. Args: using_url (str): REST HTTP endpoint filters (List[str]): Creates an "event group" in Syncthing to only receive events that have been subscribed to. limit (int): The number of ...
[ "A", "long", "-", "polling", "method", "that", "queries", "Syncthing", "for", "events", ".." ]
a7f4930f86f7543cd96990277945467896fb523d
https://github.com/blakev/python-syncthing/blob/a7f4930f86f7543cd96990277945467896fb523d/syncthing/__init__.py#L816-L870
49,330
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/rst/dis/disfilewriter.py
subtree_leaf_positions
def subtree_leaf_positions(subtree): """Return tree positions of all leaves of a subtree.""" relative_leaf_positions = subtree.treepositions('leaves') subtree_root_pos = subtree.treeposition() absolute_leaf_positions = [] for rel_leaf_pos in relative_leaf_positions: absolute_leaf_positions.a...
python
def subtree_leaf_positions(subtree): """Return tree positions of all leaves of a subtree.""" relative_leaf_positions = subtree.treepositions('leaves') subtree_root_pos = subtree.treeposition() absolute_leaf_positions = [] for rel_leaf_pos in relative_leaf_positions: absolute_leaf_positions.a...
[ "def", "subtree_leaf_positions", "(", "subtree", ")", ":", "relative_leaf_positions", "=", "subtree", ".", "treepositions", "(", "'leaves'", ")", "subtree_root_pos", "=", "subtree", ".", "treeposition", "(", ")", "absolute_leaf_positions", "=", "[", "]", "for", "r...
Return tree positions of all leaves of a subtree.
[ "Return", "tree", "positions", "of", "all", "leaves", "of", "a", "subtree", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/rst/dis/disfilewriter.py#L77-L84
49,331
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/rst/dis/disfilewriter.py
DisFileWriter.to_dis_format
def to_dis_format(self): """Return a string representation of the tree in .dis format.""" dis_raw_str = self.disfiletree.pformat() return re.sub('_!(.*?)_!', join_lines, dis_raw_str, flags=re.DOTALL)
python
def to_dis_format(self): """Return a string representation of the tree in .dis format.""" dis_raw_str = self.disfiletree.pformat() return re.sub('_!(.*?)_!', join_lines, dis_raw_str, flags=re.DOTALL)
[ "def", "to_dis_format", "(", "self", ")", ":", "dis_raw_str", "=", "self", ".", "disfiletree", ".", "pformat", "(", ")", "return", "re", ".", "sub", "(", "'_!(.*?)_!'", ",", "join_lines", ",", "dis_raw_str", ",", "flags", "=", "re", ".", "DOTALL", ")" ]
Return a string representation of the tree in .dis format.
[ "Return", "a", "string", "representation", "of", "the", "tree", "in", ".", "dis", "format", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/rst/dis/disfilewriter.py#L30-L33
49,332
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/graphml.py
write_graphml
def write_graphml(docgraph, output_file): """ takes a document graph, converts it into GraphML format and writes it to a file. """ dg_copy = deepcopy(docgraph) layerset2str(dg_copy) attriblist2str(dg_copy) remove_root_metadata(dg_copy) nx_write_graphml(dg_copy, output_file)
python
def write_graphml(docgraph, output_file): """ takes a document graph, converts it into GraphML format and writes it to a file. """ dg_copy = deepcopy(docgraph) layerset2str(dg_copy) attriblist2str(dg_copy) remove_root_metadata(dg_copy) nx_write_graphml(dg_copy, output_file)
[ "def", "write_graphml", "(", "docgraph", ",", "output_file", ")", ":", "dg_copy", "=", "deepcopy", "(", "docgraph", ")", "layerset2str", "(", "dg_copy", ")", "attriblist2str", "(", "dg_copy", ")", "remove_root_metadata", "(", "dg_copy", ")", "nx_write_graphml", ...
takes a document graph, converts it into GraphML format and writes it to a file.
[ "takes", "a", "document", "graph", "converts", "it", "into", "GraphML", "format", "and", "writes", "it", "to", "a", "file", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/graphml.py#L16-L25
49,333
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/exportxml.py
ExportXMLDocumentGraph.parse_child_elements
def parse_child_elements(self, element): '''parses all children of an etree element''' for child in element.iterchildren(): self.parsers[child.tag](child)
python
def parse_child_elements(self, element): '''parses all children of an etree element''' for child in element.iterchildren(): self.parsers[child.tag](child)
[ "def", "parse_child_elements", "(", "self", ",", "element", ")", ":", "for", "child", "in", "element", ".", "iterchildren", "(", ")", ":", "self", ".", "parsers", "[", "child", ".", "tag", "]", "(", "child", ")" ]
parses all children of an etree element
[ "parses", "all", "children", "of", "an", "etree", "element" ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/exportxml.py#L242-L245
49,334
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/exportxml.py
ExportXMLDocumentGraph.parse_descedant_elements
def parse_descedant_elements(self, element): '''parses all descendants of an etree element''' for descendant in element.iterdescendants(): self.parsers[descendant.tag](descendant)
python
def parse_descedant_elements(self, element): '''parses all descendants of an etree element''' for descendant in element.iterdescendants(): self.parsers[descendant.tag](descendant)
[ "def", "parse_descedant_elements", "(", "self", ",", "element", ")", ":", "for", "descendant", "in", "element", ".", "iterdescendants", "(", ")", ":", "self", ".", "parsers", "[", "descendant", ".", "tag", "]", "(", "descendant", ")" ]
parses all descendants of an etree element
[ "parses", "all", "descendants", "of", "an", "etree", "element" ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/exportxml.py#L247-L250
49,335
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/exportxml.py
ExportXMLDocumentGraph.add_discrel
def add_discrel(self, discrel): """ Add a discourse relation to the document graph. Parameters ---------- add_discrel : etree.Element etree representation of a <discRel> element which describes the relation between two EDUs. The ID of the othe...
python
def add_discrel(self, discrel): """ Add a discourse relation to the document graph. Parameters ---------- add_discrel : etree.Element etree representation of a <discRel> element which describes the relation between two EDUs. The ID of the othe...
[ "def", "add_discrel", "(", "self", ",", "discrel", ")", ":", "if", "self", ".", "ignore_relations", "is", "False", ":", "arg1_id", "=", "self", ".", "get_element_id", "(", "discrel", ")", "arg2_id", "=", "discrel", ".", "attrib", "[", "'arg2'", "]", "rel...
Add a discourse relation to the document graph. Parameters ---------- add_discrel : etree.Element etree representation of a <discRel> element which describes the relation between two EDUs. The ID of the other EDU is given in the arg2 attribute. No...
[ "Add", "a", "discourse", "relation", "to", "the", "document", "graph", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/exportxml.py#L275-L319
49,336
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/exportxml.py
ExportXMLDocumentGraph.get_parent_id
def get_parent_id(element): """returns the ID of the parent of the given element""" if 'parent' in element.attrib: return element.attrib['parent'] else: return element.getparent().attrib[add_ns('id')]
python
def get_parent_id(element): """returns the ID of the parent of the given element""" if 'parent' in element.attrib: return element.attrib['parent'] else: return element.getparent().attrib[add_ns('id')]
[ "def", "get_parent_id", "(", "element", ")", ":", "if", "'parent'", "in", "element", ".", "attrib", ":", "return", "element", ".", "attrib", "[", "'parent'", "]", "else", ":", "return", "element", ".", "getparent", "(", ")", ".", "attrib", "[", "add_ns",...
returns the ID of the parent of the given element
[ "returns", "the", "ID", "of", "the", "parent", "of", "the", "given", "element" ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/exportxml.py#L694-L699
49,337
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/exportxml.py
ExportXMLDocumentGraph.get_sentence_id
def get_sentence_id(self, element): """returns the ID of the sentence the given element belongs to.""" try: sentence_elem = element.iterancestors('sentence').next() except StopIteration as e: warnings.warn("<{}> element is not a descendant of a <sentence> " ...
python
def get_sentence_id(self, element): """returns the ID of the sentence the given element belongs to.""" try: sentence_elem = element.iterancestors('sentence').next() except StopIteration as e: warnings.warn("<{}> element is not a descendant of a <sentence> " ...
[ "def", "get_sentence_id", "(", "self", ",", "element", ")", ":", "try", ":", "sentence_elem", "=", "element", ".", "iterancestors", "(", "'sentence'", ")", ".", "next", "(", ")", "except", "StopIteration", "as", "e", ":", "warnings", ".", "warn", "(", "\...
returns the ID of the sentence the given element belongs to.
[ "returns", "the", "ID", "of", "the", "sentence", "the", "given", "element", "belongs", "to", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/exportxml.py#L701-L710
49,338
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/rst/rs3/rs3filewriter.py
get_node_type
def get_node_type(dgtree): """Returns the type of the root node of a DGParentedTree.""" if is_leaf(dgtree): return TreeNodeTypes.leaf_node root_label = dgtree.label() if root_label == '': assert dgtree == DGParentedTree('', []), \ "The tree has no root label, but isn't empty...
python
def get_node_type(dgtree): """Returns the type of the root node of a DGParentedTree.""" if is_leaf(dgtree): return TreeNodeTypes.leaf_node root_label = dgtree.label() if root_label == '': assert dgtree == DGParentedTree('', []), \ "The tree has no root label, but isn't empty...
[ "def", "get_node_type", "(", "dgtree", ")", ":", "if", "is_leaf", "(", "dgtree", ")", ":", "return", "TreeNodeTypes", ".", "leaf_node", "root_label", "=", "dgtree", ".", "label", "(", ")", "if", "root_label", "==", "''", ":", "assert", "dgtree", "==", "D...
Returns the type of the root node of a DGParentedTree.
[ "Returns", "the", "type", "of", "the", "root", "node", "of", "a", "DGParentedTree", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/rst/rs3/rs3filewriter.py#L28-L42
49,339
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/rst/rs3/rs3filewriter.py
RS3FileWriter.get_children_treepos
def get_children_treepos(self, treepos): """Given a treeposition, return the treepositions of its children.""" children_treepos = [] for i, child in enumerate(self.dgtree[treepos]): if isinstance(child, nltk.Tree): children_treepos.append(child.treeposition()) ...
python
def get_children_treepos(self, treepos): """Given a treeposition, return the treepositions of its children.""" children_treepos = [] for i, child in enumerate(self.dgtree[treepos]): if isinstance(child, nltk.Tree): children_treepos.append(child.treeposition()) ...
[ "def", "get_children_treepos", "(", "self", ",", "treepos", ")", ":", "children_treepos", "=", "[", "]", "for", "i", ",", "child", "in", "enumerate", "(", "self", ".", "dgtree", "[", "treepos", "]", ")", ":", "if", "isinstance", "(", "child", ",", "nlt...
Given a treeposition, return the treepositions of its children.
[ "Given", "a", "treeposition", "return", "the", "treepositions", "of", "its", "children", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/rst/rs3/rs3filewriter.py#L81-L93
49,340
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/rst/rs3/rs3filewriter.py
RS3FileWriter.get_siblings_treepos
def get_siblings_treepos(self, treepos): """Given a treeposition, return the treepositions of its siblings.""" parent_pos = self.get_parent_treepos(treepos) siblings_treepos = [] if parent_pos is not None: for child_treepos in self.get_children_treepos(parent_pos): ...
python
def get_siblings_treepos(self, treepos): """Given a treeposition, return the treepositions of its siblings.""" parent_pos = self.get_parent_treepos(treepos) siblings_treepos = [] if parent_pos is not None: for child_treepos in self.get_children_treepos(parent_pos): ...
[ "def", "get_siblings_treepos", "(", "self", ",", "treepos", ")", ":", "parent_pos", "=", "self", ".", "get_parent_treepos", "(", "treepos", ")", "siblings_treepos", "=", "[", "]", "if", "parent_pos", "is", "not", "None", ":", "for", "child_treepos", "in", "s...
Given a treeposition, return the treepositions of its siblings.
[ "Given", "a", "treeposition", "return", "the", "treepositions", "of", "its", "siblings", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/rst/rs3/rs3filewriter.py#L95-L104
49,341
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/rst/rs3/rs3filewriter.py
RS3FileWriter.get_cousins_treepos
def get_cousins_treepos(self, treepos): """Given a treeposition, return the treeposition of its siblings.""" cousins_pos = [] mother_pos = self.get_parent_treepos(treepos) if mother_pos is not None: aunts_pos = self.get_siblings_treepos(mother_pos) for aunt_pos i...
python
def get_cousins_treepos(self, treepos): """Given a treeposition, return the treeposition of its siblings.""" cousins_pos = [] mother_pos = self.get_parent_treepos(treepos) if mother_pos is not None: aunts_pos = self.get_siblings_treepos(mother_pos) for aunt_pos i...
[ "def", "get_cousins_treepos", "(", "self", ",", "treepos", ")", ":", "cousins_pos", "=", "[", "]", "mother_pos", "=", "self", ".", "get_parent_treepos", "(", "treepos", ")", "if", "mother_pos", "is", "not", "None", ":", "aunts_pos", "=", "self", ".", "get_...
Given a treeposition, return the treeposition of its siblings.
[ "Given", "a", "treeposition", "return", "the", "treeposition", "of", "its", "siblings", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/rst/rs3/rs3filewriter.py#L106-L115
49,342
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/rst/rs3/rs3filewriter.py
RS3FileWriter.get_parent_label
def get_parent_label(self, treepos): """Given the treeposition of a node, return the label of its parent. Returns None, if the tree has no parent. """ parent_pos = self.get_parent_treepos(treepos) if parent_pos is not None: parent = self.dgtree[parent_pos] ...
python
def get_parent_label(self, treepos): """Given the treeposition of a node, return the label of its parent. Returns None, if the tree has no parent. """ parent_pos = self.get_parent_treepos(treepos) if parent_pos is not None: parent = self.dgtree[parent_pos] ...
[ "def", "get_parent_label", "(", "self", ",", "treepos", ")", ":", "parent_pos", "=", "self", ".", "get_parent_treepos", "(", "treepos", ")", "if", "parent_pos", "is", "not", "None", ":", "parent", "=", "self", ".", "dgtree", "[", "parent_pos", "]", "return...
Given the treeposition of a node, return the label of its parent. Returns None, if the tree has no parent.
[ "Given", "the", "treeposition", "of", "a", "node", "return", "the", "label", "of", "its", "parent", ".", "Returns", "None", "if", "the", "tree", "has", "no", "parent", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/rst/rs3/rs3filewriter.py#L117-L126
49,343
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/rst/rs3/rs3filewriter.py
RS3FileWriter.get_children_labels
def get_children_labels(self, treepos): """Given the treeposition of a node, return the labels of its children.""" children_labels = [] node = self.dgtree[treepos] for child in node: if is_leaf(child): # we can't call .label() on a leaf node ch...
python
def get_children_labels(self, treepos): """Given the treeposition of a node, return the labels of its children.""" children_labels = [] node = self.dgtree[treepos] for child in node: if is_leaf(child): # we can't call .label() on a leaf node ch...
[ "def", "get_children_labels", "(", "self", ",", "treepos", ")", ":", "children_labels", "=", "[", "]", "node", "=", "self", ".", "dgtree", "[", "treepos", "]", "for", "child", "in", "node", ":", "if", "is_leaf", "(", "child", ")", ":", "# we can't call ....
Given the treeposition of a node, return the labels of its children.
[ "Given", "the", "treeposition", "of", "a", "node", "return", "the", "labels", "of", "its", "children", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/rst/rs3/rs3filewriter.py#L128-L138
49,344
arne-cl/discoursegraphs
src/discoursegraphs/util.py
natural_sort_key
def natural_sort_key(s): """ returns a key that can be used in sort functions. Example: >>> items = ['A99', 'a1', 'a2', 'a10', 'a24', 'a12', 'a100'] The normal sort function will ignore the natural order of the integers in the string: >>> print sorted(items) ['A99', 'a1', 'a10', 'a10...
python
def natural_sort_key(s): """ returns a key that can be used in sort functions. Example: >>> items = ['A99', 'a1', 'a2', 'a10', 'a24', 'a12', 'a100'] The normal sort function will ignore the natural order of the integers in the string: >>> print sorted(items) ['A99', 'a1', 'a10', 'a10...
[ "def", "natural_sort_key", "(", "s", ")", ":", "return", "[", "int", "(", "text", ")", "if", "text", ".", "isdigit", "(", ")", "else", "text", "for", "text", "in", "re", ".", "split", "(", "INTEGER_RE", ",", "str", "(", "s", ")", ")", "]" ]
returns a key that can be used in sort functions. Example: >>> items = ['A99', 'a1', 'a2', 'a10', 'a24', 'a12', 'a100'] The normal sort function will ignore the natural order of the integers in the string: >>> print sorted(items) ['A99', 'a1', 'a10', 'a100', 'a12', 'a2', 'a24'] When we ...
[ "returns", "a", "key", "that", "can", "be", "used", "in", "sort", "functions", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/util.py#L70-L91
49,345
arne-cl/discoursegraphs
src/discoursegraphs/util.py
ensure_unicode
def ensure_unicode(str_or_unicode): """ tests, if the input is ``str`` or ``unicode``. if it is ``str``, it will be decoded from ``UTF-8`` to unicode. """ if isinstance(str_or_unicode, str): return str_or_unicode.decode('utf-8') elif isinstance(str_or_unicode, unicode): return st...
python
def ensure_unicode(str_or_unicode): """ tests, if the input is ``str`` or ``unicode``. if it is ``str``, it will be decoded from ``UTF-8`` to unicode. """ if isinstance(str_or_unicode, str): return str_or_unicode.decode('utf-8') elif isinstance(str_or_unicode, unicode): return st...
[ "def", "ensure_unicode", "(", "str_or_unicode", ")", ":", "if", "isinstance", "(", "str_or_unicode", ",", "str", ")", ":", "return", "str_or_unicode", ".", "decode", "(", "'utf-8'", ")", "elif", "isinstance", "(", "str_or_unicode", ",", "unicode", ")", ":", ...
tests, if the input is ``str`` or ``unicode``. if it is ``str``, it will be decoded from ``UTF-8`` to unicode.
[ "tests", "if", "the", "input", "is", "str", "or", "unicode", ".", "if", "it", "is", "str", "it", "will", "be", "decoded", "from", "UTF", "-", "8", "to", "unicode", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/util.py#L94-L106
49,346
arne-cl/discoursegraphs
src/discoursegraphs/util.py
ensure_utf8
def ensure_utf8(str_or_unicode): """ tests, if the input is ``str`` or ``unicode``. if it is ``unicode``, it will be encoded from ``unicode`` to ``utf-8``. otherwise, the input string is returned. """ if isinstance(str_or_unicode, str): return str_or_unicode elif isinstance(str_or_un...
python
def ensure_utf8(str_or_unicode): """ tests, if the input is ``str`` or ``unicode``. if it is ``unicode``, it will be encoded from ``unicode`` to ``utf-8``. otherwise, the input string is returned. """ if isinstance(str_or_unicode, str): return str_or_unicode elif isinstance(str_or_un...
[ "def", "ensure_utf8", "(", "str_or_unicode", ")", ":", "if", "isinstance", "(", "str_or_unicode", ",", "str", ")", ":", "return", "str_or_unicode", "elif", "isinstance", "(", "str_or_unicode", ",", "unicode", ")", ":", "return", "str_or_unicode", ".", "encode", ...
tests, if the input is ``str`` or ``unicode``. if it is ``unicode``, it will be encoded from ``unicode`` to ``utf-8``. otherwise, the input string is returned.
[ "tests", "if", "the", "input", "is", "str", "or", "unicode", ".", "if", "it", "is", "unicode", "it", "will", "be", "encoded", "from", "unicode", "to", "utf", "-", "8", ".", "otherwise", "the", "input", "string", "is", "returned", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/util.py#L109-L122
49,347
arne-cl/discoursegraphs
src/discoursegraphs/util.py
create_dir
def create_dir(path): """ Creates a directory. Warns, if the directory can't be accessed. Passes, if the directory already exists. modified from http://stackoverflow.com/a/600612 Parameters ---------- path : str path to the directory to be created """ import sys import ...
python
def create_dir(path): """ Creates a directory. Warns, if the directory can't be accessed. Passes, if the directory already exists. modified from http://stackoverflow.com/a/600612 Parameters ---------- path : str path to the directory to be created """ import sys import ...
[ "def", "create_dir", "(", "path", ")", ":", "import", "sys", "import", "errno", "try", ":", "os", ".", "makedirs", "(", "path", ")", "except", "OSError", "as", "exc", ":", "# Python >2.5", "if", "exc", ".", "errno", "==", "errno", ".", "EEXIST", ":", ...
Creates a directory. Warns, if the directory can't be accessed. Passes, if the directory already exists. modified from http://stackoverflow.com/a/600612 Parameters ---------- path : str path to the directory to be created
[ "Creates", "a", "directory", ".", "Warns", "if", "the", "directory", "can", "t", "be", "accessed", ".", "Passes", "if", "the", "directory", "already", "exists", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/util.py#L195-L222
49,348
arne-cl/discoursegraphs
src/discoursegraphs/util.py
make_labels_explicit
def make_labels_explicit(docgraph): """ Appends the node ID to each node label and appends the edge type to each edge label in the given document graph. This can be used to debug a graph visually with ``write_dot``. Parameters ---------- docgraph : DiscourseDocumentGraph document gr...
python
def make_labels_explicit(docgraph): """ Appends the node ID to each node label and appends the edge type to each edge label in the given document graph. This can be used to debug a graph visually with ``write_dot``. Parameters ---------- docgraph : DiscourseDocumentGraph document gr...
[ "def", "make_labels_explicit", "(", "docgraph", ")", ":", "def", "make_nodelabels_explicit", "(", "docgraph", ")", ":", "for", "node_id", ",", "node_attribs", "in", "docgraph", ".", "nodes", "(", "data", "=", "True", ")", ":", "if", "'label'", "in", "docgrap...
Appends the node ID to each node label and appends the edge type to each edge label in the given document graph. This can be used to debug a graph visually with ``write_dot``. Parameters ---------- docgraph : DiscourseDocumentGraph document graph from which the nodes will be extracted ...
[ "Appends", "the", "node", "ID", "to", "each", "node", "label", "and", "appends", "the", "edge", "type", "to", "each", "edge", "label", "in", "the", "given", "document", "graph", ".", "This", "can", "be", "used", "to", "debug", "a", "graph", "visually", ...
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/util.py#L278-L312
49,349
arne-cl/discoursegraphs
src/discoursegraphs/util.py
create_multiple_replace_func
def create_multiple_replace_func(*args, **kwds): """ You can call this function and pass it a dictionary, or any other combination of arguments you could pass to built-in dict in order to construct a dictionary. The function will return a xlat closure that takes as its only argument text the string ...
python
def create_multiple_replace_func(*args, **kwds): """ You can call this function and pass it a dictionary, or any other combination of arguments you could pass to built-in dict in order to construct a dictionary. The function will return a xlat closure that takes as its only argument text the string ...
[ "def", "create_multiple_replace_func", "(", "*", "args", ",", "*", "*", "kwds", ")", ":", "adict", "=", "dict", "(", "*", "args", ",", "*", "*", "kwds", ")", "rx", "=", "re", ".", "compile", "(", "'|'", ".", "join", "(", "map", "(", "re", ".", ...
You can call this function and pass it a dictionary, or any other combination of arguments you could pass to built-in dict in order to construct a dictionary. The function will return a xlat closure that takes as its only argument text the string on which the substitutions are desired and returns a copy...
[ "You", "can", "call", "this", "function", "and", "pass", "it", "a", "dictionary", "or", "any", "other", "combination", "of", "arguments", "you", "could", "pass", "to", "built", "-", "in", "dict", "in", "order", "to", "construct", "a", "dictionary", ".", ...
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/util.py#L378-L397
49,350
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/conano.py
get_connective
def get_connective(docgraph, unit_id): """ returns the lowercased string of the connective used in the given Conano unit. """ unit_index, _unit_type = unit_id.split(':') connective_id = unit_index+':connective' return ' '.join(docgraph.get_token(tok_id).lower() for tok_id in ...
python
def get_connective(docgraph, unit_id): """ returns the lowercased string of the connective used in the given Conano unit. """ unit_index, _unit_type = unit_id.split(':') connective_id = unit_index+':connective' return ' '.join(docgraph.get_token(tok_id).lower() for tok_id in ...
[ "def", "get_connective", "(", "docgraph", ",", "unit_id", ")", ":", "unit_index", ",", "_unit_type", "=", "unit_id", ".", "split", "(", "':'", ")", "connective_id", "=", "unit_index", "+", "':connective'", "return", "' '", ".", "join", "(", "docgraph", ".", ...
returns the lowercased string of the connective used in the given Conano unit.
[ "returns", "the", "lowercased", "string", "of", "the", "connective", "used", "in", "the", "given", "Conano", "unit", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/conano.py#L193-L200
49,351
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/conano.py
ConanoDocumentGraph._add_token
def _add_token(self, token, parent_node='root'): """add a token to this docgraph""" if parent_node == 'root': parent_node = self.root token_node_id = 'token:{}'.format(self.token_count) self.add_node(token_node_id, layers={self.ns, self.ns+':token'}, at...
python
def _add_token(self, token, parent_node='root'): """add a token to this docgraph""" if parent_node == 'root': parent_node = self.root token_node_id = 'token:{}'.format(self.token_count) self.add_node(token_node_id, layers={self.ns, self.ns+':token'}, at...
[ "def", "_add_token", "(", "self", ",", "token", ",", "parent_node", "=", "'root'", ")", ":", "if", "parent_node", "==", "'root'", ":", "parent_node", "=", "self", ".", "root", "token_node_id", "=", "'token:{}'", ".", "format", "(", "self", ".", "token_coun...
add a token to this docgraph
[ "add", "a", "token", "to", "this", "docgraph" ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/conano.py#L134-L146
49,352
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/anaphoricity.py
AnaphoraDocumentGraph.__add_token_to_document
def __add_token_to_document(self, token, token_id, connected): """ adds a token to the document graph as a node with the given ID. Parameters ---------- token : str the token to be added to the document graph token_id : int the node ID of the toke...
python
def __add_token_to_document(self, token, token_id, connected): """ adds a token to the document graph as a node with the given ID. Parameters ---------- token : str the token to be added to the document graph token_id : int the node ID of the toke...
[ "def", "__add_token_to_document", "(", "self", ",", "token", ",", "token_id", ",", "connected", ")", ":", "regex_match", "=", "ANNOTATED_ANAPHORA_REGEX", ".", "search", "(", "token", ")", "if", "regex_match", ":", "# token is annotated", "unannotated_token", "=", ...
adds a token to the document graph as a node with the given ID. Parameters ---------- token : str the token to be added to the document graph token_id : int the node ID of the token to be added, which must not yet exist in the document graph c...
[ "adds", "a", "token", "to", "the", "document", "graph", "as", "a", "node", "with", "the", "given", "ID", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/anaphoricity.py#L107-L145
49,353
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/dot.py
_preprocess_nodes_for_pydot
def _preprocess_nodes_for_pydot(nodes_with_data): """throw away all node attributes, except for 'label'""" for (node_id, attrs) in nodes_with_data: if 'label' in attrs: yield (quote_for_pydot(node_id), {'label': quote_for_pydot(attrs['label'])}) else: y...
python
def _preprocess_nodes_for_pydot(nodes_with_data): """throw away all node attributes, except for 'label'""" for (node_id, attrs) in nodes_with_data: if 'label' in attrs: yield (quote_for_pydot(node_id), {'label': quote_for_pydot(attrs['label'])}) else: y...
[ "def", "_preprocess_nodes_for_pydot", "(", "nodes_with_data", ")", ":", "for", "(", "node_id", ",", "attrs", ")", "in", "nodes_with_data", ":", "if", "'label'", "in", "attrs", ":", "yield", "(", "quote_for_pydot", "(", "node_id", ")", ",", "{", "'label'", ":...
throw away all node attributes, except for 'label
[ "throw", "away", "all", "node", "attributes", "except", "for", "label" ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/dot.py#L38-L45
49,354
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/dot.py
_preprocess_edges_for_pydot
def _preprocess_edges_for_pydot(edges_with_data): """throw away all edge attributes, except for 'label'""" for (source, target, attrs) in edges_with_data: if 'label' in attrs: yield (quote_for_pydot(source), quote_for_pydot(target), {'label': quote_for_pydot(attrs['label']...
python
def _preprocess_edges_for_pydot(edges_with_data): """throw away all edge attributes, except for 'label'""" for (source, target, attrs) in edges_with_data: if 'label' in attrs: yield (quote_for_pydot(source), quote_for_pydot(target), {'label': quote_for_pydot(attrs['label']...
[ "def", "_preprocess_edges_for_pydot", "(", "edges_with_data", ")", ":", "for", "(", "source", ",", "target", ",", "attrs", ")", "in", "edges_with_data", ":", "if", "'label'", "in", "attrs", ":", "yield", "(", "quote_for_pydot", "(", "source", ")", ",", "quot...
throw away all edge attributes, except for 'label
[ "throw", "away", "all", "edge", "attributes", "except", "for", "label" ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/dot.py#L48-L55
49,355
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/dot.py
print_dot
def print_dot(docgraph): """ converts a document graph into a dot file and returns it as a string. If this function call is prepended by %dotstr, it will display the given document graph as a dot/graphviz graph in the currently running IPython notebook session. To use this function, the gvmagi...
python
def print_dot(docgraph): """ converts a document graph into a dot file and returns it as a string. If this function call is prepended by %dotstr, it will display the given document graph as a dot/graphviz graph in the currently running IPython notebook session. To use this function, the gvmagi...
[ "def", "print_dot", "(", "docgraph", ")", ":", "stripped_graph", "=", "preprocess_for_pydot", "(", "docgraph", ")", "return", "nx", ".", "drawing", ".", "nx_pydot", ".", "to_pydot", "(", "stripped_graph", ")", ".", "to_string", "(", ")" ]
converts a document graph into a dot file and returns it as a string. If this function call is prepended by %dotstr, it will display the given document graph as a dot/graphviz graph in the currently running IPython notebook session. To use this function, the gvmagic IPython notebook extension need...
[ "converts", "a", "document", "graph", "into", "a", "dot", "file", "and", "returns", "it", "as", "a", "string", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/dot.py#L84-L103
49,356
arne-cl/discoursegraphs
src/discoursegraphs/relabel.py
relabel_nodes
def relabel_nodes(G, mapping, copy=True): """Relabel the nodes of the graph G. Parameters ---------- G : graph A NetworkX graph mapping : dictionary A dictionary with the old labels as keys and new labels as values. A partial mapping is allowed. copy : bool (optional, def...
python
def relabel_nodes(G, mapping, copy=True): """Relabel the nodes of the graph G. Parameters ---------- G : graph A NetworkX graph mapping : dictionary A dictionary with the old labels as keys and new labels as values. A partial mapping is allowed. copy : bool (optional, def...
[ "def", "relabel_nodes", "(", "G", ",", "mapping", ",", "copy", "=", "True", ")", ":", "# you can pass a function f(old_label)->new_label", "# but we'll just make a dictionary here regardless", "if", "not", "hasattr", "(", "mapping", ",", "\"__getitem__\"", ")", ":", "m"...
Relabel the nodes of the graph G. Parameters ---------- G : graph A NetworkX graph mapping : dictionary A dictionary with the old labels as keys and new labels as values. A partial mapping is allowed. copy : bool (optional, default=True) If True return a copy, or if Fa...
[ "Relabel", "the", "nodes", "of", "the", "graph", "G", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/relabel.py#L25-L93
49,357
arne-cl/discoursegraphs
src/discoursegraphs/relabel.py
convert_node_labels_to_integers
def convert_node_labels_to_integers(G, first_label=0, ordering="default", label_attribute=None): """Return a copy of the graph G with the nodes relabeled with integers. Parameters ---------- G : graph A NetworkX graph first_label : int, optional (default=...
python
def convert_node_labels_to_integers(G, first_label=0, ordering="default", label_attribute=None): """Return a copy of the graph G with the nodes relabeled with integers. Parameters ---------- G : graph A NetworkX graph first_label : int, optional (default=...
[ "def", "convert_node_labels_to_integers", "(", "G", ",", "first_label", "=", "0", ",", "ordering", "=", "\"default\"", ",", "label_attribute", "=", "None", ")", ":", "N", "=", "G", ".", "number_of_nodes", "(", ")", "+", "first_label", "if", "ordering", "==",...
Return a copy of the graph G with the nodes relabeled with integers. Parameters ---------- G : graph A NetworkX graph first_label : int, optional (default=0) An integer specifying the offset in numbering nodes. The n new integer labels are numbered first_label, ..., n-1+first_labe...
[ "Return", "a", "copy", "of", "the", "graph", "G", "with", "the", "nodes", "relabeled", "with", "integers", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/relabel.py#L152-L207
49,358
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/exmaralda.py
ExmaraldaFile.write
def write(self, output_filepath): """ serialize the ExmaraldaFile instance and write it to a file. Parameters ---------- output_filepath : str relative or absolute path to the Exmaralda file to be created """ with open(output_filepath, 'w') as out_fil...
python
def write(self, output_filepath): """ serialize the ExmaraldaFile instance and write it to a file. Parameters ---------- output_filepath : str relative or absolute path to the Exmaralda file to be created """ with open(output_filepath, 'w') as out_fil...
[ "def", "write", "(", "self", ",", "output_filepath", ")", ":", "with", "open", "(", "output_filepath", ",", "'w'", ")", "as", "out_file", ":", "out_file", ".", "write", "(", "self", ".", "__str__", "(", ")", ")" ]
serialize the ExmaraldaFile instance and write it to a file. Parameters ---------- output_filepath : str relative or absolute path to the Exmaralda file to be created
[ "serialize", "the", "ExmaraldaFile", "instance", "and", "write", "it", "to", "a", "file", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/exmaralda.py#L55-L65
49,359
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/exmaralda.py
ExmaraldaFile.__create_document_header
def __create_document_header(self): """ Look, mum! XML generation without string concatenation!1!! This creates an empty, but functional header for an Exmaralda *.exb file. """ E = self.E root = E('basic-transcription') head = E('head') meta = E(...
python
def __create_document_header(self): """ Look, mum! XML generation without string concatenation!1!! This creates an empty, but functional header for an Exmaralda *.exb file. """ E = self.E root = E('basic-transcription') head = E('head') meta = E(...
[ "def", "__create_document_header", "(", "self", ")", ":", "E", "=", "self", ".", "E", "root", "=", "E", "(", "'basic-transcription'", ")", "head", "=", "E", "(", "'head'", ")", "meta", "=", "E", "(", "'meta-information'", ")", "project", "=", "E", "(",...
Look, mum! XML generation without string concatenation!1!! This creates an empty, but functional header for an Exmaralda *.exb file.
[ "Look", "mum!", "XML", "generation", "without", "string", "concatenation!1!!" ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/exmaralda.py#L67-L96
49,360
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/exmaralda.py
ExmaraldaFile.__add_document_structure
def __add_document_structure(self, docgraph, remove_redundant_layers=True): """return an Exmaralda XML etree representation a docgraph""" E = self.E root = self.__create_document_header() body = E('basic-body') timeline = E('common-timeline') ...
python
def __add_document_structure(self, docgraph, remove_redundant_layers=True): """return an Exmaralda XML etree representation a docgraph""" E = self.E root = self.__create_document_header() body = E('basic-body') timeline = E('common-timeline') ...
[ "def", "__add_document_structure", "(", "self", ",", "docgraph", ",", "remove_redundant_layers", "=", "True", ")", ":", "E", "=", "self", ".", "E", "root", "=", "self", ".", "__create_document_header", "(", ")", "body", "=", "E", "(", "'basic-body'", ")", ...
return an Exmaralda XML etree representation a docgraph
[ "return", "an", "Exmaralda", "XML", "etree", "representation", "a", "docgraph" ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/exmaralda.py#L98-L125
49,361
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/exmaralda.py
ExmaraldaDocumentGraph.__add_tokenization
def __add_tokenization(self, tree): """adds a node for each token ID in the document""" for token_id in self.get_token_ids(tree): self.add_node(token_id, layers={self.ns}) self.tokens.append(token_id)
python
def __add_tokenization(self, tree): """adds a node for each token ID in the document""" for token_id in self.get_token_ids(tree): self.add_node(token_id, layers={self.ns}) self.tokens.append(token_id)
[ "def", "__add_tokenization", "(", "self", ",", "tree", ")", ":", "for", "token_id", "in", "self", ".", "get_token_ids", "(", "tree", ")", ":", "self", ".", "add_node", "(", "token_id", ",", "layers", "=", "{", "self", ".", "ns", "}", ")", "self", "."...
adds a node for each token ID in the document
[ "adds", "a", "node", "for", "each", "token", "ID", "in", "the", "document" ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/exmaralda.py#L316-L320
49,362
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/exmaralda.py
ExmaraldaDocumentGraph.is_token_annotation_tier
def is_token_annotation_tier(self, tier): """ returns True, iff all events in the given tier annotate exactly one token. """ for i, event in enumerate(tier.iter('event')): if self.indexdelta(event.attrib['end'], event.attrib['start']) != 1: return Fals...
python
def is_token_annotation_tier(self, tier): """ returns True, iff all events in the given tier annotate exactly one token. """ for i, event in enumerate(tier.iter('event')): if self.indexdelta(event.attrib['end'], event.attrib['start']) != 1: return Fals...
[ "def", "is_token_annotation_tier", "(", "self", ",", "tier", ")", ":", "for", "i", ",", "event", "in", "enumerate", "(", "tier", ".", "iter", "(", "'event'", ")", ")", ":", "if", "self", ".", "indexdelta", "(", "event", ".", "attrib", "[", "'end'", "...
returns True, iff all events in the given tier annotate exactly one token.
[ "returns", "True", "iff", "all", "events", "in", "the", "given", "tier", "annotate", "exactly", "one", "token", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/exmaralda.py#L356-L364
49,363
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/exmaralda.py
ExmaraldaDocumentGraph.__add_token_annotation_tier
def __add_token_annotation_tier(self, tier): """ adds a tier to the document graph, in which each event annotates exactly one token. """ for i, event in enumerate(tier.iter('event')): anno_key = '{0}:{1}'.format(self.ns, tier.attrib['category']) anno_val =...
python
def __add_token_annotation_tier(self, tier): """ adds a tier to the document graph, in which each event annotates exactly one token. """ for i, event in enumerate(tier.iter('event')): anno_key = '{0}:{1}'.format(self.ns, tier.attrib['category']) anno_val =...
[ "def", "__add_token_annotation_tier", "(", "self", ",", "tier", ")", ":", "for", "i", ",", "event", "in", "enumerate", "(", "tier", ".", "iter", "(", "'event'", ")", ")", ":", "anno_key", "=", "'{0}:{1}'", ".", "format", "(", "self", ".", "ns", ",", ...
adds a tier to the document graph, in which each event annotates exactly one token.
[ "adds", "a", "tier", "to", "the", "document", "graph", "in", "which", "each", "event", "annotates", "exactly", "one", "token", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/exmaralda.py#L366-L374
49,364
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/exmaralda.py
ExmaraldaDocumentGraph.__add_span_tier
def __add_span_tier(self, tier): """ adds a tier to the document graph in which each event annotates a span of one or more tokens. """ tier_id = tier.attrib['id'] # add the tier's root node with an inbound edge from the document root self.add_node( tie...
python
def __add_span_tier(self, tier): """ adds a tier to the document graph in which each event annotates a span of one or more tokens. """ tier_id = tier.attrib['id'] # add the tier's root node with an inbound edge from the document root self.add_node( tie...
[ "def", "__add_span_tier", "(", "self", ",", "tier", ")", ":", "tier_id", "=", "tier", ".", "attrib", "[", "'id'", "]", "# add the tier's root node with an inbound edge from the document root", "self", ".", "add_node", "(", "tier_id", ",", "layers", "=", "{", "self...
adds a tier to the document graph in which each event annotates a span of one or more tokens.
[ "adds", "a", "tier", "to", "the", "document", "graph", "in", "which", "each", "event", "annotates", "a", "span", "of", "one", "or", "more", "tokens", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/exmaralda.py#L376-L405
49,365
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/exmaralda.py
ExmaraldaDocumentGraph.get_token_ids
def get_token_ids(tree): """ returns a list of all token IDs occuring the the given exmaralda file, sorted by their time stamp in ascending order. """ def tok2time(token_element): ''' extracts the time (float) of a <tli> element (i.e. the absol...
python
def get_token_ids(tree): """ returns a list of all token IDs occuring the the given exmaralda file, sorted by their time stamp in ascending order. """ def tok2time(token_element): ''' extracts the time (float) of a <tli> element (i.e. the absol...
[ "def", "get_token_ids", "(", "tree", ")", ":", "def", "tok2time", "(", "token_element", ")", ":", "'''\n extracts the time (float) of a <tli> element\n (i.e. the absolute position of a token in the document)\n '''", "return", "float", "(", "token_elem...
returns a list of all token IDs occuring the the given exmaralda file, sorted by their time stamp in ascending order.
[ "returns", "a", "list", "of", "all", "token", "IDs", "occuring", "the", "the", "given", "exmaralda", "file", "sorted", "by", "their", "time", "stamp", "in", "ascending", "order", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/exmaralda.py#L408-L423
49,366
arne-cl/discoursegraphs
src/discoursegraphs/discoursegraph.py
create_token_mapping
def create_token_mapping(docgraph_with_old_names, docgraph_with_new_names, verbose=False): """ given two document graphs which annotate the same text and which use the same tokenization, creates a dictionary with a mapping from the token IDs used in the first graph to the token ...
python
def create_token_mapping(docgraph_with_old_names, docgraph_with_new_names, verbose=False): """ given two document graphs which annotate the same text and which use the same tokenization, creates a dictionary with a mapping from the token IDs used in the first graph to the token ...
[ "def", "create_token_mapping", "(", "docgraph_with_old_names", ",", "docgraph_with_new_names", ",", "verbose", "=", "False", ")", ":", "def", "kwic_string", "(", "docgraph", ",", "keyword_index", ")", ":", "tokens", "=", "[", "tok", "for", "(", "tokid", ",", "...
given two document graphs which annotate the same text and which use the same tokenization, creates a dictionary with a mapping from the token IDs used in the first graph to the token IDs used in the second graph. Parameters ---------- docgraph_with_old_names : DiscourseDocumentGraph a docu...
[ "given", "two", "document", "graphs", "which", "annotate", "the", "same", "text", "and", "which", "use", "the", "same", "tokenization", "creates", "a", "dictionary", "with", "a", "mapping", "from", "the", "token", "IDs", "used", "in", "the", "first", "graph"...
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/discoursegraph.py#L790-L838
49,367
arne-cl/discoursegraphs
src/discoursegraphs/discoursegraph.py
get_kwic
def get_kwic(tokens, index, context_window=5): """ keyword in context Parameters ---------- tokens : list of str a text represented as a list of tokens index : int the index of the keyword in the token list context_window : int the number of preceding/succeding words...
python
def get_kwic(tokens, index, context_window=5): """ keyword in context Parameters ---------- tokens : list of str a text represented as a list of tokens index : int the index of the keyword in the token list context_window : int the number of preceding/succeding words...
[ "def", "get_kwic", "(", "tokens", ",", "index", ",", "context_window", "=", "5", ")", ":", "text_length", "=", "len", "(", "tokens", ")", "start_before", "=", "max", "(", "0", ",", "index", "-", "context_window", ")", "end_before", "=", "max", "(", "0"...
keyword in context Parameters ---------- tokens : list of str a text represented as a list of tokens index : int the index of the keyword in the token list context_window : int the number of preceding/succeding words of the keyword to be retrieved Returns --...
[ "keyword", "in", "context" ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/discoursegraph.py#L843-L873
49,368
arne-cl/discoursegraphs
src/discoursegraphs/discoursegraph.py
get_span_offsets
def get_span_offsets(docgraph, node_id): """ returns the character start and end position of the span of text that the given node spans or dominates. Returns ------- offsets : tuple(int, int) character onset and offset of the span """ try: span = get_span(docgraph, node_...
python
def get_span_offsets(docgraph, node_id): """ returns the character start and end position of the span of text that the given node spans or dominates. Returns ------- offsets : tuple(int, int) character onset and offset of the span """ try: span = get_span(docgraph, node_...
[ "def", "get_span_offsets", "(", "docgraph", ",", "node_id", ")", ":", "try", ":", "span", "=", "get_span", "(", "docgraph", ",", "node_id", ")", "# workaround for issue #138", "# TODO: when #138 is fixed, just take the first onset / last offset", "onsets", ",", "offsets",...
returns the character start and end position of the span of text that the given node spans or dominates. Returns ------- offsets : tuple(int, int) character onset and offset of the span
[ "returns", "the", "character", "start", "and", "end", "position", "of", "the", "span", "of", "text", "that", "the", "given", "node", "spans", "or", "dominates", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/discoursegraph.py#L941-L959
49,369
arne-cl/discoursegraphs
src/discoursegraphs/discoursegraph.py
get_span
def get_span(docgraph, node_id, debug=False): """ returns all the tokens that are dominated or in a span relation with the given node. If debug is set to True, you'll get a warning if the graph is cyclic. Returns ------- span : list of str sorted list of token nodes (token node IDs)...
python
def get_span(docgraph, node_id, debug=False): """ returns all the tokens that are dominated or in a span relation with the given node. If debug is set to True, you'll get a warning if the graph is cyclic. Returns ------- span : list of str sorted list of token nodes (token node IDs)...
[ "def", "get_span", "(", "docgraph", ",", "node_id", ",", "debug", "=", "False", ")", ":", "if", "debug", "is", "True", "and", "is_directed_acyclic_graph", "(", "docgraph", ")", "is", "False", ":", "warnings", ".", "warn", "(", "(", "\"Can't reliably extract ...
returns all the tokens that are dominated or in a span relation with the given node. If debug is set to True, you'll get a warning if the graph is cyclic. Returns ------- span : list of str sorted list of token nodes (token node IDs)
[ "returns", "all", "the", "tokens", "that", "are", "dominated", "or", "in", "a", "span", "relation", "with", "the", "given", "node", ".", "If", "debug", "is", "set", "to", "True", "you", "ll", "get", "a", "warning", "if", "the", "graph", "is", "cyclic",...
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/discoursegraph.py#L962-L989
49,370
arne-cl/discoursegraphs
src/discoursegraphs/discoursegraph.py
istoken
def istoken(docgraph, node_id, namespace=None): """returns true, iff the given node ID belongs to a token node. Parameters ---------- node_id : str the node to be checked namespace : str or None If a namespace is given, only look for tokens in the given namespace. Otherwise,...
python
def istoken(docgraph, node_id, namespace=None): """returns true, iff the given node ID belongs to a token node. Parameters ---------- node_id : str the node to be checked namespace : str or None If a namespace is given, only look for tokens in the given namespace. Otherwise,...
[ "def", "istoken", "(", "docgraph", ",", "node_id", ",", "namespace", "=", "None", ")", ":", "if", "namespace", "is", "None", ":", "namespace", "=", "docgraph", ".", "ns", "return", "namespace", "+", "':token'", "in", "docgraph", ".", "node", "[", "node_i...
returns true, iff the given node ID belongs to a token node. Parameters ---------- node_id : str the node to be checked namespace : str or None If a namespace is given, only look for tokens in the given namespace. Otherwise, look for tokens in the default namespace of the given ...
[ "returns", "true", "iff", "the", "given", "node", "ID", "belongs", "to", "a", "token", "node", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/discoursegraph.py#L1016-L1030
49,371
arne-cl/discoursegraphs
src/discoursegraphs/discoursegraph.py
is_continuous
def is_continuous(docgraph, dominating_node): """return True, if the tokens dominated by the given node are all adjacent""" first_onset, last_offset = get_span_offsets(docgraph, dominating_node) span_range = xrange(first_onset, last_offset+1) token_offsets = (docgraph.get_offsets(tok) ...
python
def is_continuous(docgraph, dominating_node): """return True, if the tokens dominated by the given node are all adjacent""" first_onset, last_offset = get_span_offsets(docgraph, dominating_node) span_range = xrange(first_onset, last_offset+1) token_offsets = (docgraph.get_offsets(tok) ...
[ "def", "is_continuous", "(", "docgraph", ",", "dominating_node", ")", ":", "first_onset", ",", "last_offset", "=", "get_span_offsets", "(", "docgraph", ",", "dominating_node", ")", "span_range", "=", "xrange", "(", "first_onset", ",", "last_offset", "+", "1", ")...
return True, if the tokens dominated by the given node are all adjacent
[ "return", "True", "if", "the", "tokens", "dominated", "by", "the", "given", "node", "are", "all", "adjacent" ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/discoursegraph.py#L1033-L1045
49,372
arne-cl/discoursegraphs
src/discoursegraphs/discoursegraph.py
select_edges
def select_edges(docgraph, conditions, data): """yields all edges that meet the conditions given as eval strings""" for (src_id, target_id, edge_attribs) in docgraph.edges(data=True): # if all conditions are fulfilled # we need to add edge_attribs to the namespace eval is working in if a...
python
def select_edges(docgraph, conditions, data): """yields all edges that meet the conditions given as eval strings""" for (src_id, target_id, edge_attribs) in docgraph.edges(data=True): # if all conditions are fulfilled # we need to add edge_attribs to the namespace eval is working in if a...
[ "def", "select_edges", "(", "docgraph", ",", "conditions", ",", "data", ")", ":", "for", "(", "src_id", ",", "target_id", ",", "edge_attribs", ")", "in", "docgraph", ".", "edges", "(", "data", "=", "True", ")", ":", "# if all conditions are fulfilled", "# we...
yields all edges that meet the conditions given as eval strings
[ "yields", "all", "edges", "that", "meet", "the", "conditions", "given", "as", "eval", "strings" ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/discoursegraph.py#L1191-L1201
49,373
arne-cl/discoursegraphs
src/discoursegraphs/discoursegraph.py
DiscourseDocumentGraph.add_offsets
def add_offsets(self, offset_ns=None): """ adds the onset and offset to each token in the document graph, i.e. the character position where each token starts and ends. """ if offset_ns is None: offset_ns = self.ns onset = 0 offset = 0 for tok...
python
def add_offsets(self, offset_ns=None): """ adds the onset and offset to each token in the document graph, i.e. the character position where each token starts and ends. """ if offset_ns is None: offset_ns = self.ns onset = 0 offset = 0 for tok...
[ "def", "add_offsets", "(", "self", ",", "offset_ns", "=", "None", ")", ":", "if", "offset_ns", "is", "None", ":", "offset_ns", "=", "self", ".", "ns", "onset", "=", "0", "offset", "=", "0", "for", "token_id", ",", "token_str", "in", "self", ".", "get...
adds the onset and offset to each token in the document graph, i.e. the character position where each token starts and ends.
[ "adds", "the", "onset", "and", "offset", "to", "each", "token", "in", "the", "document", "graph", "i", ".", "e", ".", "the", "character", "position", "where", "each", "token", "starts", "and", "ends", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/discoursegraph.py#L98-L113
49,374
arne-cl/discoursegraphs
src/discoursegraphs/discoursegraph.py
DiscourseDocumentGraph.add_node
def add_node(self, n, layers=None, attr_dict=None, **attr): """Add a single node n and update node attributes. Parameters ---------- n : node A node can be any hashable Python object except None. layers : set of str or None the set of layers the node belo...
python
def add_node(self, n, layers=None, attr_dict=None, **attr): """Add a single node n and update node attributes. Parameters ---------- n : node A node can be any hashable Python object except None. layers : set of str or None the set of layers the node belo...
[ "def", "add_node", "(", "self", ",", "n", ",", "layers", "=", "None", ",", "attr_dict", "=", "None", ",", "*", "*", "attr", ")", ":", "if", "not", "layers", ":", "layers", "=", "{", "self", ".", "ns", "}", "assert", "isinstance", "(", "layers", "...
Add a single node n and update node attributes. Parameters ---------- n : node A node can be any hashable Python object except None. layers : set of str or None the set of layers the node belongs to, e.g. {'tiger:token', 'anaphoricity:annotation'}. ...
[ "Add", "a", "single", "node", "n", "and", "update", "node", "attributes", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/discoursegraph.py#L192-L273
49,375
arne-cl/discoursegraphs
src/discoursegraphs/discoursegraph.py
DiscourseDocumentGraph.add_nodes_from
def add_nodes_from(self, nodes, **attr): """Add multiple nodes. Parameters ---------- nodes : iterable container A container of nodes (list, dict, set, etc.). OR A container of (node, attribute dict) tuples. Node attributes are updated usi...
python
def add_nodes_from(self, nodes, **attr): """Add multiple nodes. Parameters ---------- nodes : iterable container A container of nodes (list, dict, set, etc.). OR A container of (node, attribute dict) tuples. Node attributes are updated usi...
[ "def", "add_nodes_from", "(", "self", ",", "nodes", ",", "*", "*", "attr", ")", ":", "additional_attribs", "=", "attr", "# will be added to each node", "for", "n", "in", "nodes", ":", "try", ":", "# check, if n is a node_id or a (node_id, attrib dict) tuple", "newnode...
Add multiple nodes. Parameters ---------- nodes : iterable container A container of nodes (list, dict, set, etc.). OR A container of (node, attribute dict) tuples. Node attributes are updated using the attribute dict. attr : keyword argume...
[ "Add", "multiple", "nodes", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/discoursegraph.py#L275-L362
49,376
arne-cl/discoursegraphs
src/discoursegraphs/discoursegraph.py
DiscourseDocumentGraph.add_layer
def add_layer(self, element, layer): """ add a layer to an existing node or edge Parameters ---------- element : str, int, (str/int, str/int) the ID of a node or edge (source node ID, target node ID) layer : str the layer that the element shall be...
python
def add_layer(self, element, layer): """ add a layer to an existing node or edge Parameters ---------- element : str, int, (str/int, str/int) the ID of a node or edge (source node ID, target node ID) layer : str the layer that the element shall be...
[ "def", "add_layer", "(", "self", ",", "element", ",", "layer", ")", ":", "assert", "isinstance", "(", "layer", ",", "str", ")", ",", "\"Layers must be strings!\"", "if", "isinstance", "(", "element", ",", "tuple", ")", ":", "# edge repr. by (source, target)", ...
add a layer to an existing node or edge Parameters ---------- element : str, int, (str/int, str/int) the ID of a node or edge (source node ID, target node ID) layer : str the layer that the element shall be added to
[ "add", "a", "layer", "to", "an", "existing", "node", "or", "edge" ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/discoursegraph.py#L614-L640
49,377
arne-cl/discoursegraphs
src/discoursegraphs/discoursegraph.py
DiscourseDocumentGraph.get_token
def get_token(self, token_node_id, token_attrib='token'): """ given a token node ID, returns the token unicode string. Parameters ---------- token_node_id : str the ID of the token node token_attrib : str name of the node attribute that contains t...
python
def get_token(self, token_node_id, token_attrib='token'): """ given a token node ID, returns the token unicode string. Parameters ---------- token_node_id : str the ID of the token node token_attrib : str name of the node attribute that contains t...
[ "def", "get_token", "(", "self", ",", "token_node_id", ",", "token_attrib", "=", "'token'", ")", ":", "return", "self", ".", "node", "[", "token_node_id", "]", "[", "self", ".", "ns", "+", "':'", "+", "token_attrib", "]" ]
given a token node ID, returns the token unicode string. Parameters ---------- token_node_id : str the ID of the token node token_attrib : str name of the node attribute that contains the token string as its value (default: token). Returns ...
[ "given", "a", "token", "node", "ID", "returns", "the", "token", "unicode", "string", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/discoursegraph.py#L643-L660
49,378
arne-cl/discoursegraphs
src/discoursegraphs/discoursegraph.py
DiscourseDocumentGraph.merge_rootnodes
def merge_rootnodes(self, other_docgraph): """ Copy all the metadata from the root node of the other graph into this one. Then, move all edges belonging to the other root node to this one. Finally, remove the root node of the other graph from this one. """ # copy metadata...
python
def merge_rootnodes(self, other_docgraph): """ Copy all the metadata from the root node of the other graph into this one. Then, move all edges belonging to the other root node to this one. Finally, remove the root node of the other graph from this one. """ # copy metadata...
[ "def", "merge_rootnodes", "(", "self", ",", "other_docgraph", ")", ":", "# copy metadata from other graph, cf. #136", "if", "'metadata'", "in", "other_docgraph", ".", "node", "[", "other_docgraph", ".", "root", "]", ":", "other_meta", "=", "other_docgraph", ".", "no...
Copy all the metadata from the root node of the other graph into this one. Then, move all edges belonging to the other root node to this one. Finally, remove the root node of the other graph from this one.
[ "Copy", "all", "the", "metadata", "from", "the", "root", "node", "of", "the", "other", "graph", "into", "this", "one", ".", "Then", "move", "all", "edges", "belonging", "to", "the", "other", "root", "node", "to", "this", "one", ".", "Finally", "remove", ...
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/discoursegraph.py#L725-L743
49,379
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/paulaxml/paula.py
paula_etree_to_string
def paula_etree_to_string(tree, dtd_filename): """convert a PAULA etree into an XML string.""" return etree.tostring( tree, pretty_print=True, xml_declaration=True, encoding="UTF-8", standalone='no', doctype='<!DOCTYPE paula SYSTEM "{0}">'.format(dtd_filename))
python
def paula_etree_to_string(tree, dtd_filename): """convert a PAULA etree into an XML string.""" return etree.tostring( tree, pretty_print=True, xml_declaration=True, encoding="UTF-8", standalone='no', doctype='<!DOCTYPE paula SYSTEM "{0}">'.format(dtd_filename))
[ "def", "paula_etree_to_string", "(", "tree", ",", "dtd_filename", ")", ":", "return", "etree", ".", "tostring", "(", "tree", ",", "pretty_print", "=", "True", ",", "xml_declaration", "=", "True", ",", "encoding", "=", "\"UTF-8\"", ",", "standalone", "=", "'n...
convert a PAULA etree into an XML string.
[ "convert", "a", "PAULA", "etree", "into", "an", "XML", "string", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/paulaxml/paula.py#L580-L585
49,380
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/paulaxml/paula.py
gen_paula_etree
def gen_paula_etree(paula_id): """ creates an element tree representation of an empty PAULA XML file. """ E = ElementMaker(nsmap=NSMAP) tree = E('paula', version='1.1') tree.append(E('header', paula_id=paula_id)) return E, tree
python
def gen_paula_etree(paula_id): """ creates an element tree representation of an empty PAULA XML file. """ E = ElementMaker(nsmap=NSMAP) tree = E('paula', version='1.1') tree.append(E('header', paula_id=paula_id)) return E, tree
[ "def", "gen_paula_etree", "(", "paula_id", ")", ":", "E", "=", "ElementMaker", "(", "nsmap", "=", "NSMAP", ")", "tree", "=", "E", "(", "'paula'", ",", "version", "=", "'1.1'", ")", "tree", ".", "append", "(", "E", "(", "'header'", ",", "paula_id", "=...
creates an element tree representation of an empty PAULA XML file.
[ "creates", "an", "element", "tree", "representation", "of", "an", "empty", "PAULA", "XML", "file", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/paulaxml/paula.py#L588-L595
49,381
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/paulaxml/paula.py
write_paula
def write_paula(docgraph, output_root_dir, human_readable=False): """ converts a DiscourseDocumentGraph into a set of PAULA XML files representing the same document. Parameters ---------- docgraph : DiscourseDocumentGraph the document graph to be converted """ paula_document = P...
python
def write_paula(docgraph, output_root_dir, human_readable=False): """ converts a DiscourseDocumentGraph into a set of PAULA XML files representing the same document. Parameters ---------- docgraph : DiscourseDocumentGraph the document graph to be converted """ paula_document = P...
[ "def", "write_paula", "(", "docgraph", ",", "output_root_dir", ",", "human_readable", "=", "False", ")", ":", "paula_document", "=", "PaulaDocument", "(", "docgraph", ",", "human_readable", "=", "human_readable", ")", "error_msg", "=", "(", "\"Please specify an outp...
converts a DiscourseDocumentGraph into a set of PAULA XML files representing the same document. Parameters ---------- docgraph : DiscourseDocumentGraph the document graph to be converted
[ "converts", "a", "DiscourseDocumentGraph", "into", "a", "set", "of", "PAULA", "XML", "files", "representing", "the", "same", "document", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/paulaxml/paula.py#L617-L638
49,382
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/paulaxml/paula.py
PaulaDocument.__make_xpointer_compatible
def __make_xpointer_compatible(self): """ ensure that all node and IDs in the document graph are valid xpointer IDs. this will relabel all node IDs in place in the discourse graph and change its ``.tokens`` list accordingly. """ node_id_map = {node: ensure_xpointer_compa...
python
def __make_xpointer_compatible(self): """ ensure that all node and IDs in the document graph are valid xpointer IDs. this will relabel all node IDs in place in the discourse graph and change its ``.tokens`` list accordingly. """ node_id_map = {node: ensure_xpointer_compa...
[ "def", "__make_xpointer_compatible", "(", "self", ")", ":", "node_id_map", "=", "{", "node", ":", "ensure_xpointer_compatibility", "(", "node", ")", "for", "node", "in", "self", ".", "dg", ".", "nodes_iter", "(", ")", "}", "old_token_ids", "=", "self", ".", ...
ensure that all node and IDs in the document graph are valid xpointer IDs. this will relabel all node IDs in place in the discourse graph and change its ``.tokens`` list accordingly.
[ "ensure", "that", "all", "node", "and", "IDs", "in", "the", "document", "graph", "are", "valid", "xpointer", "IDs", ".", "this", "will", "relabel", "all", "node", "IDs", "in", "place", "in", "the", "discourse", "graph", "and", "change", "its", ".", "toke...
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/paulaxml/paula.py#L122-L135
49,383
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/salt/labels.py
SaltLabel.from_etree
def from_etree(cls, etree_element): """ creates a ``SaltLabel`` from an etree element representing a label element in a SaltXMI file. A label element in SaltXMI looks like this:: <labels xsi:type="saltCore:SFeature" namespace="salt" name="SNAME" value="ACED0...
python
def from_etree(cls, etree_element): """ creates a ``SaltLabel`` from an etree element representing a label element in a SaltXMI file. A label element in SaltXMI looks like this:: <labels xsi:type="saltCore:SFeature" namespace="salt" name="SNAME" value="ACED0...
[ "def", "from_etree", "(", "cls", ",", "etree_element", ")", ":", "return", "cls", "(", "name", "=", "etree_element", ".", "attrib", "[", "'name'", "]", ",", "value", "=", "etree_element", ".", "attrib", "[", "'valueString'", "]", ",", "xsi_type", "=", "g...
creates a ``SaltLabel`` from an etree element representing a label element in a SaltXMI file. A label element in SaltXMI looks like this:: <labels xsi:type="saltCore:SFeature" namespace="salt" name="SNAME" value="ACED0005740007735370616E3139" valueString="sS...
[ "creates", "a", "SaltLabel", "from", "an", "etree", "element", "representing", "a", "label", "element", "in", "a", "SaltXMI", "file", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/salt/labels.py#L54-L74
49,384
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/brackets.py
write_brackets
def write_brackets(docgraph, output_file, layer='mmax'): """ converts a document graph into a plain text file with brackets. Parameters ---------- layer : str or None The layer from which the pointing chains/relations (i.e. coreference relations) should be extracted. If no l...
python
def write_brackets(docgraph, output_file, layer='mmax'): """ converts a document graph into a plain text file with brackets. Parameters ---------- layer : str or None The layer from which the pointing chains/relations (i.e. coreference relations) should be extracted. If no l...
[ "def", "write_brackets", "(", "docgraph", ",", "output_file", ",", "layer", "=", "'mmax'", ")", ":", "bracketed_str", "=", "gen_bracketed_output", "(", "docgraph", ",", "layer", "=", "layer", ")", "assert", "isinstance", "(", "output_file", ",", "(", "str", ...
converts a document graph into a plain text file with brackets. Parameters ---------- layer : str or None The layer from which the pointing chains/relations (i.e. coreference relations) should be extracted. If no layer is selected, all pointing relations will be considered. ...
[ "converts", "a", "document", "graph", "into", "a", "plain", "text", "file", "with", "brackets", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/brackets.py#L126-L149
49,385
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/geoff.py
node2geoff
def node2geoff(node_name, properties, encoder): """converts a NetworkX node into a Geoff string. Parameters ---------- node_name : str or int the ID of a NetworkX node properties : dict a dictionary of node attributes encoder : json.JSONEncoder an instance of a JSON enco...
python
def node2geoff(node_name, properties, encoder): """converts a NetworkX node into a Geoff string. Parameters ---------- node_name : str or int the ID of a NetworkX node properties : dict a dictionary of node attributes encoder : json.JSONEncoder an instance of a JSON enco...
[ "def", "node2geoff", "(", "node_name", ",", "properties", ",", "encoder", ")", ":", "if", "properties", ":", "return", "'({0} {1})'", ".", "format", "(", "node_name", ",", "encoder", ".", "encode", "(", "properties", ")", ")", "else", ":", "return", "'({0}...
converts a NetworkX node into a Geoff string. Parameters ---------- node_name : str or int the ID of a NetworkX node properties : dict a dictionary of node attributes encoder : json.JSONEncoder an instance of a JSON encoder (e.g. `json.JSONEncoder`) Returns ------- ...
[ "converts", "a", "NetworkX", "node", "into", "a", "Geoff", "string", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/geoff.py#L13-L34
49,386
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/geoff.py
edge2geoff
def edge2geoff(from_node, to_node, properties, edge_relationship_name, encoder): """converts a NetworkX edge into a Geoff string. Parameters ---------- from_node : str or int the ID of a NetworkX source node to_node : str or int the ID of a NetworkX target node properties : dict...
python
def edge2geoff(from_node, to_node, properties, edge_relationship_name, encoder): """converts a NetworkX edge into a Geoff string. Parameters ---------- from_node : str or int the ID of a NetworkX source node to_node : str or int the ID of a NetworkX target node properties : dict...
[ "def", "edge2geoff", "(", "from_node", ",", "to_node", ",", "properties", ",", "edge_relationship_name", ",", "encoder", ")", ":", "edge_string", "=", "None", "if", "properties", ":", "args", "=", "[", "from_node", ",", "edge_relationship_name", ",", "encoder", ...
converts a NetworkX edge into a Geoff string. Parameters ---------- from_node : str or int the ID of a NetworkX source node to_node : str or int the ID of a NetworkX target node properties : dict a dictionary of edge attributes edge_relationship_name : str string...
[ "converts", "a", "NetworkX", "edge", "into", "a", "Geoff", "string", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/geoff.py#L37-L67
49,387
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/rst/heilman_sagae_2015.py
get_edu_text
def get_edu_text(text_subtree): """return the text of the given EDU subtree""" assert text_subtree.label() == SubtreeType.text return u' '.join(word.decode('utf-8') for word in text_subtree.leaves())
python
def get_edu_text(text_subtree): """return the text of the given EDU subtree""" assert text_subtree.label() == SubtreeType.text return u' '.join(word.decode('utf-8') for word in text_subtree.leaves())
[ "def", "get_edu_text", "(", "text_subtree", ")", ":", "assert", "text_subtree", ".", "label", "(", ")", "==", "SubtreeType", ".", "text", "return", "u' '", ".", "join", "(", "word", ".", "decode", "(", "'utf-8'", ")", "for", "word", "in", "text_subtree", ...
return the text of the given EDU subtree
[ "return", "the", "text", "of", "the", "given", "EDU", "subtree" ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/rst/heilman_sagae_2015.py#L204-L207
49,388
arne-cl/discoursegraphs
src/discoursegraphs/readwrite/rst/heilman_sagae_2015.py
_add_edus_to_tree
def _add_edus_to_tree(parented_tree, edus): """replace EDU indices with the text of the EDUs in a parented tree. Parameters ---------- parented_tree : nltk.ParentedTree a parented tree that only contains EDU indices as leaves edus : list(list(unicode)) a list of EDUs, wh...
python
def _add_edus_to_tree(parented_tree, edus): """replace EDU indices with the text of the EDUs in a parented tree. Parameters ---------- parented_tree : nltk.ParentedTree a parented tree that only contains EDU indices as leaves edus : list(list(unicode)) a list of EDUs, wh...
[ "def", "_add_edus_to_tree", "(", "parented_tree", ",", "edus", ")", ":", "for", "i", ",", "child", "in", "enumerate", "(", "parented_tree", ")", ":", "if", "isinstance", "(", "child", ",", "nltk", ".", "Tree", ")", ":", "_add_edus_to_tree", "(", "child", ...
replace EDU indices with the text of the EDUs in a parented tree. Parameters ---------- parented_tree : nltk.ParentedTree a parented tree that only contains EDU indices as leaves edus : list(list(unicode)) a list of EDUs, where each EDU is represented as a list of to...
[ "replace", "EDU", "indices", "with", "the", "text", "of", "the", "EDUs", "in", "a", "parented", "tree", "." ]
842f0068a3190be2c75905754521b176b25a54fb
https://github.com/arne-cl/discoursegraphs/blob/842f0068a3190be2c75905754521b176b25a54fb/src/discoursegraphs/readwrite/rst/heilman_sagae_2015.py#L303-L322
49,389
ojarva/python-ledcontroller
ledcontroller/__init__.py
LedControllerPool.execute
def execute(self, controller_id, command, *args, **kwargs): """ Execute a single command, and sets sleep times properly. - controller_id = index of controller, zero-based - command is normal LedController command as a string - *args and **kwargs are passed to command Fo...
python
def execute(self, controller_id, command, *args, **kwargs): """ Execute a single command, and sets sleep times properly. - controller_id = index of controller, zero-based - command is normal LedController command as a string - *args and **kwargs are passed to command Fo...
[ "def", "execute", "(", "self", ",", "controller_id", ",", "command", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "controller_instance", "=", "self", ".", "controllers", "[", "controller_id", "]", "controller_instance", ".", "last_command_at", "=", "...
Execute a single command, and sets sleep times properly. - controller_id = index of controller, zero-based - command is normal LedController command as a string - *args and **kwargs are passed to command For example, .execute(0, "on", 1) sends "on" command to group 1 on controller 0 (f...
[ "Execute", "a", "single", "command", "and", "sets", "sleep", "times", "properly", "." ]
414de7c9b2c9d919f68fca0c0a8631ee76ec05c9
https://github.com/ojarva/python-ledcontroller/blob/414de7c9b2c9d919f68fca0c0a8631ee76ec05c9/ledcontroller/__init__.py#L33-L47
49,390
ojarva/python-ledcontroller
ledcontroller/__init__.py
LedController.set_group_type
def set_group_type(self, group, bulb_type): """ Set bulb type for specified group. Group must be int between 1 and 4. Type must be "rgbw" or "white". Alternatively, use constructor keywords group_1, group_2 etc. to set bulb types. """ if bulb_type not in ("rgbw", "whit...
python
def set_group_type(self, group, bulb_type): """ Set bulb type for specified group. Group must be int between 1 and 4. Type must be "rgbw" or "white". Alternatively, use constructor keywords group_1, group_2 etc. to set bulb types. """ if bulb_type not in ("rgbw", "whit...
[ "def", "set_group_type", "(", "self", ",", "group", ",", "bulb_type", ")", ":", "if", "bulb_type", "not", "in", "(", "\"rgbw\"", ",", "\"white\"", ")", ":", "raise", "AttributeError", "(", "\"Bulb type must be either rgbw or white\"", ")", "self", ".", "group", ...
Set bulb type for specified group. Group must be int between 1 and 4. Type must be "rgbw" or "white". Alternatively, use constructor keywords group_1, group_2 etc. to set bulb types.
[ "Set", "bulb", "type", "for", "specified", "group", "." ]
414de7c9b2c9d919f68fca0c0a8631ee76ec05c9
https://github.com/ojarva/python-ledcontroller/blob/414de7c9b2c9d919f68fca0c0a8631ee76ec05c9/ledcontroller/__init__.py#L145-L159
49,391
ojarva/python-ledcontroller
ledcontroller/__init__.py
LedController.get_brightness_level
def get_brightness_level(cls, percent): """ Convert percents to bulbs internal range. percent should be integer from 0 to 100. Return value is 2 (minimum brightness) - 27 (maximum brightness) """ # Clamp to appropriate range. percent = min(100, max(0, percent)) ...
python
def get_brightness_level(cls, percent): """ Convert percents to bulbs internal range. percent should be integer from 0 to 100. Return value is 2 (minimum brightness) - 27 (maximum brightness) """ # Clamp to appropriate range. percent = min(100, max(0, percent)) ...
[ "def", "get_brightness_level", "(", "cls", ",", "percent", ")", ":", "# Clamp to appropriate range.", "percent", "=", "min", "(", "100", ",", "max", "(", "0", ",", "percent", ")", ")", "# Map 0-100 to 2-27", "value", "=", "int", "(", "2", "+", "(", "(", ...
Convert percents to bulbs internal range. percent should be integer from 0 to 100. Return value is 2 (minimum brightness) - 27 (maximum brightness)
[ "Convert", "percents", "to", "bulbs", "internal", "range", "." ]
414de7c9b2c9d919f68fca0c0a8631ee76ec05c9
https://github.com/ojarva/python-ledcontroller/blob/414de7c9b2c9d919f68fca0c0a8631ee76ec05c9/ledcontroller/__init__.py#L319-L330
49,392
ojarva/python-ledcontroller
ledcontroller/__init__.py
LedController.set_brightness
def set_brightness(self, percent, group=None): """ Set brightness. Percent is int between 0 (minimum brightness) and 100 (maximum brightness), or float between 0.0 (minimum brightness) and 1.0 (maximum brightness). See also .nightmode(). If group (1-4) is not s...
python
def set_brightness(self, percent, group=None): """ Set brightness. Percent is int between 0 (minimum brightness) and 100 (maximum brightness), or float between 0.0 (minimum brightness) and 1.0 (maximum brightness). See also .nightmode(). If group (1-4) is not s...
[ "def", "set_brightness", "(", "self", ",", "percent", ",", "group", "=", "None", ")", ":", "# If input is float, assume it is percent value from 0 to 1.", "if", "isinstance", "(", "percent", ",", "float", ")", ":", "if", "percent", ">", "1", ":", "percent", "=",...
Set brightness. Percent is int between 0 (minimum brightness) and 100 (maximum brightness), or float between 0.0 (minimum brightness) and 1.0 (maximum brightness). See also .nightmode(). If group (1-4) is not specified, brightness of all four groups will be adjusted.
[ "Set", "brightness", "." ]
414de7c9b2c9d919f68fca0c0a8631ee76ec05c9
https://github.com/ojarva/python-ledcontroller/blob/414de7c9b2c9d919f68fca0c0a8631ee76ec05c9/ledcontroller/__init__.py#L332-L351
49,393
ojarva/python-ledcontroller
ledcontroller/__init__.py
LedController.batch_run
def batch_run(self, *commands): """ Run batch of commands in sequence. Input is positional arguments with (function pointer, *args) tuples. This method is useful for executing commands to multiple groups with retries, without having too long delays. For example, ...
python
def batch_run(self, *commands): """ Run batch of commands in sequence. Input is positional arguments with (function pointer, *args) tuples. This method is useful for executing commands to multiple groups with retries, without having too long delays. For example, ...
[ "def", "batch_run", "(", "self", ",", "*", "commands", ")", ":", "original_retries", "=", "self", ".", "repeat_commands", "self", ".", "repeat_commands", "=", "1", "for", "_", "in", "range", "(", "original_retries", ")", ":", "for", "command", "in", "comma...
Run batch of commands in sequence. Input is positional arguments with (function pointer, *args) tuples. This method is useful for executing commands to multiple groups with retries, without having too long delays. For example, - Set group 1 to red and brightness to 10%...
[ "Run", "batch", "of", "commands", "in", "sequence", "." ]
414de7c9b2c9d919f68fca0c0a8631ee76ec05c9
https://github.com/ojarva/python-ledcontroller/blob/414de7c9b2c9d919f68fca0c0a8631ee76ec05c9/ledcontroller/__init__.py#L412-L442
49,394
hharnisc/python-ddp
DDPClient.py
DDPSocket.send
def send(self, msg_dict): """Send a message through the websocket client and wait for the answer if the message being sent contains an id attribute.""" message = ejson.dumps(msg_dict) super(DDPSocket, self).send(message) self._debug_log('<<<{}'.format(message))
python
def send(self, msg_dict): """Send a message through the websocket client and wait for the answer if the message being sent contains an id attribute.""" message = ejson.dumps(msg_dict) super(DDPSocket, self).send(message) self._debug_log('<<<{}'.format(message))
[ "def", "send", "(", "self", ",", "msg_dict", ")", ":", "message", "=", "ejson", ".", "dumps", "(", "msg_dict", ")", "super", "(", "DDPSocket", ",", "self", ")", ".", "send", "(", "message", ")", "self", ".", "_debug_log", "(", "'<<<{}'", ".", "format...
Send a message through the websocket client and wait for the answer if the message being sent contains an id attribute.
[ "Send", "a", "message", "through", "the", "websocket", "client", "and", "wait", "for", "the", "answer", "if", "the", "message", "being", "sent", "contains", "an", "id", "attribute", "." ]
00bdf33c20ecba56623890515381154e14c5b757
https://github.com/hharnisc/python-ddp/blob/00bdf33c20ecba56623890515381154e14c5b757/DDPClient.py#L32-L37
49,395
hharnisc/python-ddp
DDPClient.py
DDPSocket._debug_log
def _debug_log(self, msg): """Debug log messages if debug=True""" if not self.debug: return sys.stderr.write('{}\n'.format(msg))
python
def _debug_log(self, msg): """Debug log messages if debug=True""" if not self.debug: return sys.stderr.write('{}\n'.format(msg))
[ "def", "_debug_log", "(", "self", ",", "msg", ")", ":", "if", "not", "self", ".", "debug", ":", "return", "sys", ".", "stderr", ".", "write", "(", "'{}\\n'", ".", "format", "(", "msg", ")", ")" ]
Debug log messages if debug=True
[ "Debug", "log", "messages", "if", "debug", "=", "True" ]
00bdf33c20ecba56623890515381154e14c5b757
https://github.com/hharnisc/python-ddp/blob/00bdf33c20ecba56623890515381154e14c5b757/DDPClient.py#L43-L47
49,396
hharnisc/python-ddp
DDPClient.py
DDPClient._init_socket
def _init_socket(self): """Initialize the ddp socket""" # destroy the connection if it already exists if self.ddpsocket: self.ddpsocket.remove_all_listeners('received_message') self.ddpsocket.remove_all_listeners('closed') self.ddpsocket.remove_all_listeners('...
python
def _init_socket(self): """Initialize the ddp socket""" # destroy the connection if it already exists if self.ddpsocket: self.ddpsocket.remove_all_listeners('received_message') self.ddpsocket.remove_all_listeners('closed') self.ddpsocket.remove_all_listeners('...
[ "def", "_init_socket", "(", "self", ")", ":", "# destroy the connection if it already exists", "if", "self", ".", "ddpsocket", ":", "self", ".", "ddpsocket", ".", "remove_all_listeners", "(", "'received_message'", ")", "self", ".", "ddpsocket", ".", "remove_all_listen...
Initialize the ddp socket
[ "Initialize", "the", "ddp", "socket" ]
00bdf33c20ecba56623890515381154e14c5b757
https://github.com/hharnisc/python-ddp/blob/00bdf33c20ecba56623890515381154e14c5b757/DDPClient.py#L75-L89
49,397
hharnisc/python-ddp
DDPClient.py
DDPClient._recover_network_failure
def _recover_network_failure(self): """Recover from a network failure""" if self.auto_reconnect and not self._is_closing: connected = False while not connected: log_msg = "* ATTEMPTING RECONNECT" if self._retry_new_version: log_...
python
def _recover_network_failure(self): """Recover from a network failure""" if self.auto_reconnect and not self._is_closing: connected = False while not connected: log_msg = "* ATTEMPTING RECONNECT" if self._retry_new_version: log_...
[ "def", "_recover_network_failure", "(", "self", ")", ":", "if", "self", ".", "auto_reconnect", "and", "not", "self", ".", "_is_closing", ":", "connected", "=", "False", "while", "not", "connected", ":", "log_msg", "=", "\"* ATTEMPTING RECONNECT\"", "if", "self",...
Recover from a network failure
[ "Recover", "from", "a", "network", "failure" ]
00bdf33c20ecba56623890515381154e14c5b757
https://github.com/hharnisc/python-ddp/blob/00bdf33c20ecba56623890515381154e14c5b757/DDPClient.py#L91-L110
49,398
hharnisc/python-ddp
DDPClient.py
DDPClient.opened
def opened(self): """Send the connect message to the server.""" # give up if there are no more ddp versions to try if self._ddp_version_index == len(DDP_VERSIONS): self.ddpsocket._debug_log('* DDP VERSION MISMATCH') self.emit('version_mismatch', DDP_VERSIONS) ...
python
def opened(self): """Send the connect message to the server.""" # give up if there are no more ddp versions to try if self._ddp_version_index == len(DDP_VERSIONS): self.ddpsocket._debug_log('* DDP VERSION MISMATCH') self.emit('version_mismatch', DDP_VERSIONS) ...
[ "def", "opened", "(", "self", ")", ":", "# give up if there are no more ddp versions to try", "if", "self", ".", "_ddp_version_index", "==", "len", "(", "DDP_VERSIONS", ")", ":", "self", ".", "ddpsocket", ".", "_debug_log", "(", "'* DDP VERSION MISMATCH'", ")", "sel...
Send the connect message to the server.
[ "Send", "the", "connect", "message", "to", "the", "server", "." ]
00bdf33c20ecba56623890515381154e14c5b757
https://github.com/hharnisc/python-ddp/blob/00bdf33c20ecba56623890515381154e14c5b757/DDPClient.py#L125-L148
49,399
hharnisc/python-ddp
DDPClient.py
DDPClient.closed
def closed(self, code, reason=None): """Called when the connection is closed""" self.emit('socket_closed', code, reason) self._recover_network_failure()
python
def closed(self, code, reason=None): """Called when the connection is closed""" self.emit('socket_closed', code, reason) self._recover_network_failure()
[ "def", "closed", "(", "self", ",", "code", ",", "reason", "=", "None", ")", ":", "self", ".", "emit", "(", "'socket_closed'", ",", "code", ",", "reason", ")", "self", ".", "_recover_network_failure", "(", ")" ]
Called when the connection is closed
[ "Called", "when", "the", "connection", "is", "closed" ]
00bdf33c20ecba56623890515381154e14c5b757
https://github.com/hharnisc/python-ddp/blob/00bdf33c20ecba56623890515381154e14c5b757/DDPClient.py#L150-L153