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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
10,000 | inonit/drf-haystack | drf_haystack/utils.py | merge_dict | def merge_dict(a, b):
"""
Recursively merges and returns dict a with dict b.
Any list values will be combined and returned sorted.
:param a: dictionary object
:param b: dictionary object
:return: merged dictionary object
"""
if not isinstance(b, dict):
return b
result = de... | python | def merge_dict(a, b):
"""
Recursively merges and returns dict a with dict b.
Any list values will be combined and returned sorted.
:param a: dictionary object
:param b: dictionary object
:return: merged dictionary object
"""
if not isinstance(b, dict):
return b
result = de... | [
"def",
"merge_dict",
"(",
"a",
",",
"b",
")",
":",
"if",
"not",
"isinstance",
"(",
"b",
",",
"dict",
")",
":",
"return",
"b",
"result",
"=",
"deepcopy",
"(",
"a",
")",
"for",
"key",
",",
"val",
"in",
"six",
".",
"iteritems",
"(",
"b",
")",
":",... | Recursively merges and returns dict a with dict b.
Any list values will be combined and returned sorted.
:param a: dictionary object
:param b: dictionary object
:return: merged dictionary object | [
"Recursively",
"merges",
"and",
"returns",
"dict",
"a",
"with",
"dict",
"b",
".",
"Any",
"list",
"values",
"will",
"be",
"combined",
"and",
"returned",
"sorted",
"."
] | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/utils.py#L9-L31 |
10,001 | inonit/drf-haystack | drf_haystack/generics.py | HaystackGenericAPIView.get_queryset | def get_queryset(self, index_models=[]):
"""
Get the list of items for this view.
Returns ``self.queryset`` if defined and is a ``self.object_class``
instance.
@:param index_models: override `self.index_models`
"""
if self.queryset is not None and isinstance(self... | python | def get_queryset(self, index_models=[]):
"""
Get the list of items for this view.
Returns ``self.queryset`` if defined and is a ``self.object_class``
instance.
@:param index_models: override `self.index_models`
"""
if self.queryset is not None and isinstance(self... | [
"def",
"get_queryset",
"(",
"self",
",",
"index_models",
"=",
"[",
"]",
")",
":",
"if",
"self",
".",
"queryset",
"is",
"not",
"None",
"and",
"isinstance",
"(",
"self",
".",
"queryset",
",",
"self",
".",
"object_class",
")",
":",
"queryset",
"=",
"self"... | Get the list of items for this view.
Returns ``self.queryset`` if defined and is a ``self.object_class``
instance.
@:param index_models: override `self.index_models` | [
"Get",
"the",
"list",
"of",
"items",
"for",
"this",
"view",
".",
"Returns",
"self",
".",
"queryset",
"if",
"defined",
"and",
"is",
"a",
"self",
".",
"object_class",
"instance",
"."
] | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/generics.py#L40-L56 |
10,002 | inonit/drf-haystack | drf_haystack/generics.py | HaystackGenericAPIView.get_object | def get_object(self):
"""
Fetch a single document from the data store according to whatever
unique identifier is available for that document in the
SearchIndex.
In cases where the view has multiple ``index_models``, add a ``model`` query
parameter containing a single `ap... | python | def get_object(self):
"""
Fetch a single document from the data store according to whatever
unique identifier is available for that document in the
SearchIndex.
In cases where the view has multiple ``index_models``, add a ``model`` query
parameter containing a single `ap... | [
"def",
"get_object",
"(",
"self",
")",
":",
"queryset",
"=",
"self",
".",
"get_queryset",
"(",
")",
"if",
"\"model\"",
"in",
"self",
".",
"request",
".",
"query_params",
":",
"try",
":",
"app_label",
",",
"model",
"=",
"map",
"(",
"six",
".",
"text_typ... | Fetch a single document from the data store according to whatever
unique identifier is available for that document in the
SearchIndex.
In cases where the view has multiple ``index_models``, add a ``model`` query
parameter containing a single `app_label.model` name to the request in orde... | [
"Fetch",
"a",
"single",
"document",
"from",
"the",
"data",
"store",
"according",
"to",
"whatever",
"unique",
"identifier",
"is",
"available",
"for",
"that",
"document",
"in",
"the",
"SearchIndex",
"."
] | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/generics.py#L58-L95 |
10,003 | inonit/drf-haystack | drf_haystack/mixins.py | MoreLikeThisMixin.more_like_this | def more_like_this(self, request, pk=None):
"""
Sets up a detail route for ``more-like-this`` results.
Note that you'll need backend support in order to take advantage of this.
This will add ie. ^search/{pk}/more-like-this/$ to your existing ^search pattern.
"""
obj = se... | python | def more_like_this(self, request, pk=None):
"""
Sets up a detail route for ``more-like-this`` results.
Note that you'll need backend support in order to take advantage of this.
This will add ie. ^search/{pk}/more-like-this/$ to your existing ^search pattern.
"""
obj = se... | [
"def",
"more_like_this",
"(",
"self",
",",
"request",
",",
"pk",
"=",
"None",
")",
":",
"obj",
"=",
"self",
".",
"get_object",
"(",
")",
".",
"object",
"queryset",
"=",
"self",
".",
"filter_queryset",
"(",
"self",
".",
"get_queryset",
"(",
")",
")",
... | Sets up a detail route for ``more-like-this`` results.
Note that you'll need backend support in order to take advantage of this.
This will add ie. ^search/{pk}/more-like-this/$ to your existing ^search pattern. | [
"Sets",
"up",
"a",
"detail",
"route",
"for",
"more",
"-",
"like",
"-",
"this",
"results",
".",
"Note",
"that",
"you",
"ll",
"need",
"backend",
"support",
"in",
"order",
"to",
"take",
"advantage",
"of",
"this",
"."
] | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/mixins.py#L17-L33 |
10,004 | inonit/drf-haystack | drf_haystack/mixins.py | FacetMixin.filter_facet_queryset | def filter_facet_queryset(self, queryset):
"""
Given a search queryset, filter it with whichever facet filter backends
in use.
"""
for backend in list(self.facet_filter_backends):
queryset = backend().filter_queryset(self.request, queryset, self)
if self.load... | python | def filter_facet_queryset(self, queryset):
"""
Given a search queryset, filter it with whichever facet filter backends
in use.
"""
for backend in list(self.facet_filter_backends):
queryset = backend().filter_queryset(self.request, queryset, self)
if self.load... | [
"def",
"filter_facet_queryset",
"(",
"self",
",",
"queryset",
")",
":",
"for",
"backend",
"in",
"list",
"(",
"self",
".",
"facet_filter_backends",
")",
":",
"queryset",
"=",
"backend",
"(",
")",
".",
"filter_queryset",
"(",
"self",
".",
"request",
",",
"qu... | Given a search queryset, filter it with whichever facet filter backends
in use. | [
"Given",
"a",
"search",
"queryset",
"filter",
"it",
"with",
"whichever",
"facet",
"filter",
"backends",
"in",
"use",
"."
] | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/mixins.py#L66-L77 |
10,005 | inonit/drf-haystack | drf_haystack/mixins.py | FacetMixin.get_facet_serializer | def get_facet_serializer(self, *args, **kwargs):
"""
Return the facet serializer instance that should be used for
serializing faceted output.
"""
assert "objects" in kwargs, "`objects` is a required argument to `get_facet_serializer()`"
facet_serializer_class = self.get_... | python | def get_facet_serializer(self, *args, **kwargs):
"""
Return the facet serializer instance that should be used for
serializing faceted output.
"""
assert "objects" in kwargs, "`objects` is a required argument to `get_facet_serializer()`"
facet_serializer_class = self.get_... | [
"def",
"get_facet_serializer",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"assert",
"\"objects\"",
"in",
"kwargs",
",",
"\"`objects` is a required argument to `get_facet_serializer()`\"",
"facet_serializer_class",
"=",
"self",
".",
"get_facet_seri... | Return the facet serializer instance that should be used for
serializing faceted output. | [
"Return",
"the",
"facet",
"serializer",
"instance",
"that",
"should",
"be",
"used",
"for",
"serializing",
"faceted",
"output",
"."
] | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/mixins.py#L79-L92 |
10,006 | inonit/drf-haystack | drf_haystack/mixins.py | FacetMixin.get_facet_serializer_class | def get_facet_serializer_class(self):
"""
Return the class to use for serializing facets.
Defaults to using ``self.facet_serializer_class``.
"""
if self.facet_serializer_class is None:
raise AttributeError(
"%(cls)s should either include a `facet_seria... | python | def get_facet_serializer_class(self):
"""
Return the class to use for serializing facets.
Defaults to using ``self.facet_serializer_class``.
"""
if self.facet_serializer_class is None:
raise AttributeError(
"%(cls)s should either include a `facet_seria... | [
"def",
"get_facet_serializer_class",
"(",
"self",
")",
":",
"if",
"self",
".",
"facet_serializer_class",
"is",
"None",
":",
"raise",
"AttributeError",
"(",
"\"%(cls)s should either include a `facet_serializer_class` attribute, \"",
"\"or override %(cls)s.get_facet_serializer_class(... | Return the class to use for serializing facets.
Defaults to using ``self.facet_serializer_class``. | [
"Return",
"the",
"class",
"to",
"use",
"for",
"serializing",
"facets",
".",
"Defaults",
"to",
"using",
"self",
".",
"facet_serializer_class",
"."
] | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/mixins.py#L94-L105 |
10,007 | inonit/drf-haystack | drf_haystack/mixins.py | FacetMixin.get_facet_objects_serializer | def get_facet_objects_serializer(self, *args, **kwargs):
"""
Return the serializer instance which should be used for
serializing faceted objects.
"""
facet_objects_serializer_class = self.get_facet_objects_serializer_class()
kwargs["context"] = self.get_serializer_context... | python | def get_facet_objects_serializer(self, *args, **kwargs):
"""
Return the serializer instance which should be used for
serializing faceted objects.
"""
facet_objects_serializer_class = self.get_facet_objects_serializer_class()
kwargs["context"] = self.get_serializer_context... | [
"def",
"get_facet_objects_serializer",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"facet_objects_serializer_class",
"=",
"self",
".",
"get_facet_objects_serializer_class",
"(",
")",
"kwargs",
"[",
"\"context\"",
"]",
"=",
"self",
".",
"get... | Return the serializer instance which should be used for
serializing faceted objects. | [
"Return",
"the",
"serializer",
"instance",
"which",
"should",
"be",
"used",
"for",
"serializing",
"faceted",
"objects",
"."
] | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/mixins.py#L107-L114 |
10,008 | inonit/drf-haystack | drf_haystack/fields.py | DRFHaystackFieldMixin.bind | def bind(self, field_name, parent):
"""
Initializes the field name and parent for the field instance.
Called when a field is added to the parent serializer instance.
Taken from DRF and modified to support drf_haystack multiple index
functionality.
"""
# In order ... | python | def bind(self, field_name, parent):
"""
Initializes the field name and parent for the field instance.
Called when a field is added to the parent serializer instance.
Taken from DRF and modified to support drf_haystack multiple index
functionality.
"""
# In order ... | [
"def",
"bind",
"(",
"self",
",",
"field_name",
",",
"parent",
")",
":",
"# In order to enforce a consistent style, we error if a redundant",
"# 'source' argument has been used. For example:",
"# my_field = serializer.CharField(source='my_field')",
"assert",
"self",
".",
"source",
"... | Initializes the field name and parent for the field instance.
Called when a field is added to the parent serializer instance.
Taken from DRF and modified to support drf_haystack multiple index
functionality. | [
"Initializes",
"the",
"field",
"name",
"and",
"parent",
"for",
"the",
"field",
"instance",
".",
"Called",
"when",
"a",
"field",
"is",
"added",
"to",
"the",
"parent",
"serializer",
"instance",
".",
"Taken",
"from",
"DRF",
"and",
"modified",
"to",
"support",
... | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/fields.py#L16-L50 |
10,009 | inonit/drf-haystack | drf_haystack/serializers.py | HaystackSerializer._get_default_field_kwargs | def _get_default_field_kwargs(model, field):
"""
Get the required attributes from the model field in order
to instantiate a REST Framework serializer field.
"""
kwargs = {}
try:
field_name = field.model_attr or field.index_fieldname
model_field = m... | python | def _get_default_field_kwargs(model, field):
"""
Get the required attributes from the model field in order
to instantiate a REST Framework serializer field.
"""
kwargs = {}
try:
field_name = field.model_attr or field.index_fieldname
model_field = m... | [
"def",
"_get_default_field_kwargs",
"(",
"model",
",",
"field",
")",
":",
"kwargs",
"=",
"{",
"}",
"try",
":",
"field_name",
"=",
"field",
".",
"model_attr",
"or",
"field",
".",
"index_fieldname",
"model_field",
"=",
"model",
".",
"_meta",
".",
"get_field",
... | Get the required attributes from the model field in order
to instantiate a REST Framework serializer field. | [
"Get",
"the",
"required",
"attributes",
"from",
"the",
"model",
"field",
"in",
"order",
"to",
"instantiate",
"a",
"REST",
"Framework",
"serializer",
"field",
"."
] | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/serializers.py#L124-L148 |
10,010 | inonit/drf-haystack | drf_haystack/serializers.py | HaystackSerializer._get_index_class_name | def _get_index_class_name(self, index_cls):
"""
Converts in index model class to a name suitable for use as a field name prefix. A user
may optionally specify custom aliases via an 'index_aliases' attribute on the Meta class
"""
cls_name = index_cls.__name__
aliases = sel... | python | def _get_index_class_name(self, index_cls):
"""
Converts in index model class to a name suitable for use as a field name prefix. A user
may optionally specify custom aliases via an 'index_aliases' attribute on the Meta class
"""
cls_name = index_cls.__name__
aliases = sel... | [
"def",
"_get_index_class_name",
"(",
"self",
",",
"index_cls",
")",
":",
"cls_name",
"=",
"index_cls",
".",
"__name__",
"aliases",
"=",
"self",
".",
"Meta",
".",
"index_aliases",
"return",
"aliases",
".",
"get",
"(",
"cls_name",
",",
"cls_name",
".",
"split"... | Converts in index model class to a name suitable for use as a field name prefix. A user
may optionally specify custom aliases via an 'index_aliases' attribute on the Meta class | [
"Converts",
"in",
"index",
"model",
"class",
"to",
"a",
"name",
"suitable",
"for",
"use",
"as",
"a",
"field",
"name",
"prefix",
".",
"A",
"user",
"may",
"optionally",
"specify",
"custom",
"aliases",
"via",
"an",
"index_aliases",
"attribute",
"on",
"the",
"... | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/serializers.py#L156-L163 |
10,011 | inonit/drf-haystack | drf_haystack/serializers.py | HaystackSerializer.get_fields | def get_fields(self):
"""
Get the required fields for serializing the result.
"""
fields = self.Meta.fields
exclude = self.Meta.exclude
ignore_fields = self.Meta.ignore_fields
indices = self.Meta.index_classes
declared_fields = copy.deepcopy(self._declar... | python | def get_fields(self):
"""
Get the required fields for serializing the result.
"""
fields = self.Meta.fields
exclude = self.Meta.exclude
ignore_fields = self.Meta.ignore_fields
indices = self.Meta.index_classes
declared_fields = copy.deepcopy(self._declar... | [
"def",
"get_fields",
"(",
"self",
")",
":",
"fields",
"=",
"self",
".",
"Meta",
".",
"fields",
"exclude",
"=",
"self",
".",
"Meta",
".",
"exclude",
"ignore_fields",
"=",
"self",
".",
"Meta",
".",
"ignore_fields",
"indices",
"=",
"self",
".",
"Meta",
".... | Get the required fields for serializing the result. | [
"Get",
"the",
"required",
"fields",
"for",
"serializing",
"the",
"result",
"."
] | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/serializers.py#L165-L214 |
10,012 | inonit/drf-haystack | drf_haystack/serializers.py | HaystackSerializer.to_representation | def to_representation(self, instance):
"""
If we have a serializer mapping, use that. Otherwise, use standard serializer behavior
Since we might be dealing with multiple indexes, some fields might
not be valid for all results. Do not render the fields which don't belong
to the s... | python | def to_representation(self, instance):
"""
If we have a serializer mapping, use that. Otherwise, use standard serializer behavior
Since we might be dealing with multiple indexes, some fields might
not be valid for all results. Do not render the fields which don't belong
to the s... | [
"def",
"to_representation",
"(",
"self",
",",
"instance",
")",
":",
"if",
"self",
".",
"Meta",
".",
"serializers",
":",
"ret",
"=",
"self",
".",
"multi_serializer_representation",
"(",
"instance",
")",
"else",
":",
"ret",
"=",
"super",
"(",
"HaystackSerializ... | If we have a serializer mapping, use that. Otherwise, use standard serializer behavior
Since we might be dealing with multiple indexes, some fields might
not be valid for all results. Do not render the fields which don't belong
to the search result. | [
"If",
"we",
"have",
"a",
"serializer",
"mapping",
"use",
"that",
".",
"Otherwise",
"use",
"standard",
"serializer",
"behavior",
"Since",
"we",
"might",
"be",
"dealing",
"with",
"multiple",
"indexes",
"some",
"fields",
"might",
"not",
"be",
"valid",
"for",
"a... | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/serializers.py#L216-L251 |
10,013 | inonit/drf-haystack | drf_haystack/serializers.py | FacetFieldSerializer.get_narrow_url | def get_narrow_url(self, instance):
"""
Return a link suitable for narrowing on the current item.
"""
text = instance[0]
request = self.context["request"]
query_params = request.GET.copy()
# Never keep the page query parameter in narrowing urls.
# It will... | python | def get_narrow_url(self, instance):
"""
Return a link suitable for narrowing on the current item.
"""
text = instance[0]
request = self.context["request"]
query_params = request.GET.copy()
# Never keep the page query parameter in narrowing urls.
# It will... | [
"def",
"get_narrow_url",
"(",
"self",
",",
"instance",
")",
":",
"text",
"=",
"instance",
"[",
"0",
"]",
"request",
"=",
"self",
".",
"context",
"[",
"\"request\"",
"]",
"query_params",
"=",
"request",
".",
"GET",
".",
"copy",
"(",
")",
"# Never keep the... | Return a link suitable for narrowing on the current item. | [
"Return",
"a",
"link",
"suitable",
"for",
"narrowing",
"on",
"the",
"current",
"item",
"."
] | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/serializers.py#L340-L360 |
10,014 | inonit/drf-haystack | drf_haystack/serializers.py | FacetFieldSerializer.to_representation | def to_representation(self, field, instance):
"""
Set the ``parent_field`` property equal to the current field on the serializer class,
so that each field can query it to see what kind of attribute they are processing.
"""
self.parent_field = field
return super(FacetField... | python | def to_representation(self, field, instance):
"""
Set the ``parent_field`` property equal to the current field on the serializer class,
so that each field can query it to see what kind of attribute they are processing.
"""
self.parent_field = field
return super(FacetField... | [
"def",
"to_representation",
"(",
"self",
",",
"field",
",",
"instance",
")",
":",
"self",
".",
"parent_field",
"=",
"field",
"return",
"super",
"(",
"FacetFieldSerializer",
",",
"self",
")",
".",
"to_representation",
"(",
"instance",
")"
] | Set the ``parent_field`` property equal to the current field on the serializer class,
so that each field can query it to see what kind of attribute they are processing. | [
"Set",
"the",
"parent_field",
"property",
"equal",
"to",
"the",
"current",
"field",
"on",
"the",
"serializer",
"class",
"so",
"that",
"each",
"field",
"can",
"query",
"it",
"to",
"see",
"what",
"kind",
"of",
"attribute",
"they",
"are",
"processing",
"."
] | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/serializers.py#L362-L368 |
10,015 | inonit/drf-haystack | drf_haystack/serializers.py | HaystackFacetSerializer.get_fields | def get_fields(self):
"""
This returns a dictionary containing the top most fields,
``dates``, ``fields`` and ``queries``.
"""
field_mapping = OrderedDict()
for field, data in self.instance.items():
field_mapping.update(
{field: self.facet_dict... | python | def get_fields(self):
"""
This returns a dictionary containing the top most fields,
``dates``, ``fields`` and ``queries``.
"""
field_mapping = OrderedDict()
for field, data in self.instance.items():
field_mapping.update(
{field: self.facet_dict... | [
"def",
"get_fields",
"(",
"self",
")",
":",
"field_mapping",
"=",
"OrderedDict",
"(",
")",
"for",
"field",
",",
"data",
"in",
"self",
".",
"instance",
".",
"items",
"(",
")",
":",
"field_mapping",
".",
"update",
"(",
"{",
"field",
":",
"self",
".",
"... | This returns a dictionary containing the top most fields,
``dates``, ``fields`` and ``queries``. | [
"This",
"returns",
"a",
"dictionary",
"containing",
"the",
"top",
"most",
"fields",
"dates",
"fields",
"and",
"queries",
"."
] | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/serializers.py#L384-L399 |
10,016 | inonit/drf-haystack | drf_haystack/serializers.py | HaystackFacetSerializer.get_objects | def get_objects(self, instance):
"""
Return a list of objects matching the faceted result.
"""
view = self.context["view"]
queryset = self.context["objects"]
page = view.paginate_queryset(queryset)
if page is not None:
serializer = view.get_facet_obje... | python | def get_objects(self, instance):
"""
Return a list of objects matching the faceted result.
"""
view = self.context["view"]
queryset = self.context["objects"]
page = view.paginate_queryset(queryset)
if page is not None:
serializer = view.get_facet_obje... | [
"def",
"get_objects",
"(",
"self",
",",
"instance",
")",
":",
"view",
"=",
"self",
".",
"context",
"[",
"\"view\"",
"]",
"queryset",
"=",
"self",
".",
"context",
"[",
"\"objects\"",
"]",
"page",
"=",
"view",
".",
"paginate_queryset",
"(",
"queryset",
")"... | Return a list of objects matching the faceted result. | [
"Return",
"a",
"list",
"of",
"objects",
"matching",
"the",
"faceted",
"result",
"."
] | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/serializers.py#L401-L419 |
10,017 | inonit/drf-haystack | drf_haystack/serializers.py | HighlighterMixin.get_document_field | def get_document_field(instance):
"""
Returns which field the search index has marked as it's
`document=True` field.
"""
for name, field in instance.searchindex.fields.items():
if field.document is True:
return name | python | def get_document_field(instance):
"""
Returns which field the search index has marked as it's
`document=True` field.
"""
for name, field in instance.searchindex.fields.items():
if field.document is True:
return name | [
"def",
"get_document_field",
"(",
"instance",
")",
":",
"for",
"name",
",",
"field",
"in",
"instance",
".",
"searchindex",
".",
"fields",
".",
"items",
"(",
")",
":",
"if",
"field",
".",
"document",
"is",
"True",
":",
"return",
"name"
] | Returns which field the search index has marked as it's
`document=True` field. | [
"Returns",
"which",
"field",
"the",
"search",
"index",
"has",
"marked",
"as",
"it",
"s",
"document",
"=",
"True",
"field",
"."
] | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/serializers.py#L470-L477 |
10,018 | inonit/drf-haystack | drf_haystack/filters.py | BaseHaystackFilterBackend.apply_filters | def apply_filters(self, queryset, applicable_filters=None, applicable_exclusions=None):
"""
Apply constructed filters and excludes and return the queryset
:param queryset: queryset to filter
:param applicable_filters: filters which are passed directly to queryset.filter()
:param... | python | def apply_filters(self, queryset, applicable_filters=None, applicable_exclusions=None):
"""
Apply constructed filters and excludes and return the queryset
:param queryset: queryset to filter
:param applicable_filters: filters which are passed directly to queryset.filter()
:param... | [
"def",
"apply_filters",
"(",
"self",
",",
"queryset",
",",
"applicable_filters",
"=",
"None",
",",
"applicable_exclusions",
"=",
"None",
")",
":",
"if",
"applicable_filters",
":",
"queryset",
"=",
"queryset",
".",
"filter",
"(",
"applicable_filters",
")",
"if",
... | Apply constructed filters and excludes and return the queryset
:param queryset: queryset to filter
:param applicable_filters: filters which are passed directly to queryset.filter()
:param applicable_exclusions: filters which are passed directly to queryset.exclude()
:returns filtered qu... | [
"Apply",
"constructed",
"filters",
"and",
"excludes",
"and",
"return",
"the",
"queryset"
] | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/filters.py#L27-L40 |
10,019 | inonit/drf-haystack | drf_haystack/filters.py | BaseHaystackFilterBackend.build_filters | def build_filters(self, view, filters=None):
"""
Get the query builder instance and return constructed query filters.
"""
query_builder = self.get_query_builder(backend=self, view=view)
return query_builder.build_query(**(filters if filters else {})) | python | def build_filters(self, view, filters=None):
"""
Get the query builder instance and return constructed query filters.
"""
query_builder = self.get_query_builder(backend=self, view=view)
return query_builder.build_query(**(filters if filters else {})) | [
"def",
"build_filters",
"(",
"self",
",",
"view",
",",
"filters",
"=",
"None",
")",
":",
"query_builder",
"=",
"self",
".",
"get_query_builder",
"(",
"backend",
"=",
"self",
",",
"view",
"=",
"view",
")",
"return",
"query_builder",
".",
"build_query",
"(",... | Get the query builder instance and return constructed query filters. | [
"Get",
"the",
"query",
"builder",
"instance",
"and",
"return",
"constructed",
"query",
"filters",
"."
] | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/filters.py#L42-L47 |
10,020 | inonit/drf-haystack | drf_haystack/filters.py | BaseHaystackFilterBackend.filter_queryset | def filter_queryset(self, request, queryset, view):
"""
Return the filtered queryset.
"""
applicable_filters, applicable_exclusions = self.build_filters(view, filters=self.get_request_filters(request))
return self.apply_filters(
queryset=queryset,
applicab... | python | def filter_queryset(self, request, queryset, view):
"""
Return the filtered queryset.
"""
applicable_filters, applicable_exclusions = self.build_filters(view, filters=self.get_request_filters(request))
return self.apply_filters(
queryset=queryset,
applicab... | [
"def",
"filter_queryset",
"(",
"self",
",",
"request",
",",
"queryset",
",",
"view",
")",
":",
"applicable_filters",
",",
"applicable_exclusions",
"=",
"self",
".",
"build_filters",
"(",
"view",
",",
"filters",
"=",
"self",
".",
"get_request_filters",
"(",
"re... | Return the filtered queryset. | [
"Return",
"the",
"filtered",
"queryset",
"."
] | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/filters.py#L56-L65 |
10,021 | inonit/drf-haystack | drf_haystack/filters.py | BaseHaystackFilterBackend.get_query_builder | def get_query_builder(self, *args, **kwargs):
"""
Return the query builder class instance that should be used to
build the query which is passed to the search engine backend.
"""
query_builder = self.get_query_builder_class()
return query_builder(*args, **kwargs) | python | def get_query_builder(self, *args, **kwargs):
"""
Return the query builder class instance that should be used to
build the query which is passed to the search engine backend.
"""
query_builder = self.get_query_builder_class()
return query_builder(*args, **kwargs) | [
"def",
"get_query_builder",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"query_builder",
"=",
"self",
".",
"get_query_builder_class",
"(",
")",
"return",
"query_builder",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | Return the query builder class instance that should be used to
build the query which is passed to the search engine backend. | [
"Return",
"the",
"query",
"builder",
"class",
"instance",
"that",
"should",
"be",
"used",
"to",
"build",
"the",
"query",
"which",
"is",
"passed",
"to",
"the",
"search",
"engine",
"backend",
"."
] | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/filters.py#L67-L73 |
10,022 | inonit/drf-haystack | drf_haystack/filters.py | HaystackFacetFilter.apply_filters | def apply_filters(self, queryset, applicable_filters=None, applicable_exclusions=None):
"""
Apply faceting to the queryset
"""
for field, options in applicable_filters["field_facets"].items():
queryset = queryset.facet(field, **options)
for field, options in applicab... | python | def apply_filters(self, queryset, applicable_filters=None, applicable_exclusions=None):
"""
Apply faceting to the queryset
"""
for field, options in applicable_filters["field_facets"].items():
queryset = queryset.facet(field, **options)
for field, options in applicab... | [
"def",
"apply_filters",
"(",
"self",
",",
"queryset",
",",
"applicable_filters",
"=",
"None",
",",
"applicable_exclusions",
"=",
"None",
")",
":",
"for",
"field",
",",
"options",
"in",
"applicable_filters",
"[",
"\"field_facets\"",
"]",
".",
"items",
"(",
")",... | Apply faceting to the queryset | [
"Apply",
"faceting",
"to",
"the",
"queryset"
] | ceabd0f6318f129758341ab08292a20205d6f4cd | https://github.com/inonit/drf-haystack/blob/ceabd0f6318f129758341ab08292a20205d6f4cd/drf_haystack/filters.py#L202-L215 |
10,023 | maximtrp/scikit-posthocs | scikit_posthocs/_posthocs.py | __convert_to_df | def __convert_to_df(a, val_col=None, group_col=None, val_id=None, group_id=None):
'''Hidden helper method to create a DataFrame with input data for further
processing.
Parameters
----------
a : array_like or pandas DataFrame object
An array, any object exposing the array interface or a pan... | python | def __convert_to_df(a, val_col=None, group_col=None, val_id=None, group_id=None):
'''Hidden helper method to create a DataFrame with input data for further
processing.
Parameters
----------
a : array_like or pandas DataFrame object
An array, any object exposing the array interface or a pan... | [
"def",
"__convert_to_df",
"(",
"a",
",",
"val_col",
"=",
"None",
",",
"group_col",
"=",
"None",
",",
"val_id",
"=",
"None",
",",
"group_id",
"=",
"None",
")",
":",
"if",
"not",
"group_col",
":",
"group_col",
"=",
"'groups'",
"if",
"not",
"val_col",
":"... | Hidden helper method to create a DataFrame with input data for further
processing.
Parameters
----------
a : array_like or pandas DataFrame object
An array, any object exposing the array interface or a pandas DataFrame.
Array must be two-dimensional. Second dimension may vary,
i... | [
"Hidden",
"helper",
"method",
"to",
"create",
"a",
"DataFrame",
"with",
"input",
"data",
"for",
"further",
"processing",
"."
] | 5476b09e2a325cd4e31c0b0bc6906ab5cd77fc5d | https://github.com/maximtrp/scikit-posthocs/blob/5476b09e2a325cd4e31c0b0bc6906ab5cd77fc5d/scikit_posthocs/_posthocs.py#L11-L106 |
10,024 | maximtrp/scikit-posthocs | scikit_posthocs/_posthocs.py | posthoc_tukey_hsd | def posthoc_tukey_hsd(x, g, alpha=0.05):
'''Pairwise comparisons with TukeyHSD confidence intervals. This is a
convenience function to make statsmodels `pairwise_tukeyhsd` method more
applicable for further use.
Parameters
----------
x : array_like or pandas Series object, 1d
An array,... | python | def posthoc_tukey_hsd(x, g, alpha=0.05):
'''Pairwise comparisons with TukeyHSD confidence intervals. This is a
convenience function to make statsmodels `pairwise_tukeyhsd` method more
applicable for further use.
Parameters
----------
x : array_like or pandas Series object, 1d
An array,... | [
"def",
"posthoc_tukey_hsd",
"(",
"x",
",",
"g",
",",
"alpha",
"=",
"0.05",
")",
":",
"result",
"=",
"pairwise_tukeyhsd",
"(",
"x",
",",
"g",
",",
"alpha",
"=",
"0.05",
")",
"groups",
"=",
"np",
".",
"array",
"(",
"result",
".",
"groupsunique",
",",
... | Pairwise comparisons with TukeyHSD confidence intervals. This is a
convenience function to make statsmodels `pairwise_tukeyhsd` method more
applicable for further use.
Parameters
----------
x : array_like or pandas Series object, 1d
An array, any object exposing the array interface, contain... | [
"Pairwise",
"comparisons",
"with",
"TukeyHSD",
"confidence",
"intervals",
".",
"This",
"is",
"a",
"convenience",
"function",
"to",
"make",
"statsmodels",
"pairwise_tukeyhsd",
"method",
"more",
"applicable",
"for",
"further",
"use",
"."
] | 5476b09e2a325cd4e31c0b0bc6906ab5cd77fc5d | https://github.com/maximtrp/scikit-posthocs/blob/5476b09e2a325cd4e31c0b0bc6906ab5cd77fc5d/scikit_posthocs/_posthocs.py#L1845-L1897 |
10,025 | maximtrp/scikit-posthocs | scikit_posthocs/_posthocs.py | posthoc_mannwhitney | def posthoc_mannwhitney(a, val_col=None, group_col=None, use_continuity=True, alternative='two-sided', p_adjust=None, sort=True):
'''Pairwise comparisons with Mann-Whitney rank test.
Parameters
----------
a : array_like or pandas DataFrame object
An array, any object exposing the array interfa... | python | def posthoc_mannwhitney(a, val_col=None, group_col=None, use_continuity=True, alternative='two-sided', p_adjust=None, sort=True):
'''Pairwise comparisons with Mann-Whitney rank test.
Parameters
----------
a : array_like or pandas DataFrame object
An array, any object exposing the array interfa... | [
"def",
"posthoc_mannwhitney",
"(",
"a",
",",
"val_col",
"=",
"None",
",",
"group_col",
"=",
"None",
",",
"use_continuity",
"=",
"True",
",",
"alternative",
"=",
"'two-sided'",
",",
"p_adjust",
"=",
"None",
",",
"sort",
"=",
"True",
")",
":",
"x",
",",
... | Pairwise comparisons with Mann-Whitney rank test.
Parameters
----------
a : array_like or pandas DataFrame object
An array, any object exposing the array interface or a pandas
DataFrame. Array must be two-dimensional.
val_col : str, optional
Name of a DataFrame column that cont... | [
"Pairwise",
"comparisons",
"with",
"Mann",
"-",
"Whitney",
"rank",
"test",
"."
] | 5476b09e2a325cd4e31c0b0bc6906ab5cd77fc5d | https://github.com/maximtrp/scikit-posthocs/blob/5476b09e2a325cd4e31c0b0bc6906ab5cd77fc5d/scikit_posthocs/_posthocs.py#L1900-L1991 |
10,026 | maximtrp/scikit-posthocs | scikit_posthocs/_posthocs.py | posthoc_wilcoxon | def posthoc_wilcoxon(a, val_col=None, group_col=None, zero_method='wilcox', correction=False, p_adjust=None, sort=False):
'''Pairwise comparisons with Wilcoxon signed-rank test. It is a non-parametric
version of the paired T-test for use with non-parametric ANOVA.
Parameters
----------
a : array_l... | python | def posthoc_wilcoxon(a, val_col=None, group_col=None, zero_method='wilcox', correction=False, p_adjust=None, sort=False):
'''Pairwise comparisons with Wilcoxon signed-rank test. It is a non-parametric
version of the paired T-test for use with non-parametric ANOVA.
Parameters
----------
a : array_l... | [
"def",
"posthoc_wilcoxon",
"(",
"a",
",",
"val_col",
"=",
"None",
",",
"group_col",
"=",
"None",
",",
"zero_method",
"=",
"'wilcox'",
",",
"correction",
"=",
"False",
",",
"p_adjust",
"=",
"None",
",",
"sort",
"=",
"False",
")",
":",
"x",
",",
"_val_co... | Pairwise comparisons with Wilcoxon signed-rank test. It is a non-parametric
version of the paired T-test for use with non-parametric ANOVA.
Parameters
----------
a : array_like or pandas DataFrame object
An array, any object exposing the array interface or a pandas
DataFrame. Array must... | [
"Pairwise",
"comparisons",
"with",
"Wilcoxon",
"signed",
"-",
"rank",
"test",
".",
"It",
"is",
"a",
"non",
"-",
"parametric",
"version",
"of",
"the",
"paired",
"T",
"-",
"test",
"for",
"use",
"with",
"non",
"-",
"parametric",
"ANOVA",
"."
] | 5476b09e2a325cd4e31c0b0bc6906ab5cd77fc5d | https://github.com/maximtrp/scikit-posthocs/blob/5476b09e2a325cd4e31c0b0bc6906ab5cd77fc5d/scikit_posthocs/_posthocs.py#L1994-L2086 |
10,027 | cjrh/aiorun | aiorun.py | shutdown_waits_for | def shutdown_waits_for(coro, loop=None):
"""Prevent coro from being cancelled during the shutdown sequence.
The trick here is that we add this coro to the global
"DO_NOT_CANCEL" collection, and then later during the shutdown
sequence we make sure that the task that wraps this coro will NOT
be cance... | python | def shutdown_waits_for(coro, loop=None):
"""Prevent coro from being cancelled during the shutdown sequence.
The trick here is that we add this coro to the global
"DO_NOT_CANCEL" collection, and then later during the shutdown
sequence we make sure that the task that wraps this coro will NOT
be cance... | [
"def",
"shutdown_waits_for",
"(",
"coro",
",",
"loop",
"=",
"None",
")",
":",
"loop",
"=",
"loop",
"or",
"get_event_loop",
"(",
")",
"fut",
"=",
"loop",
".",
"create_future",
"(",
")",
"# This future will connect coro and the caller.",
"async",
"def",
"coro_prox... | Prevent coro from being cancelled during the shutdown sequence.
The trick here is that we add this coro to the global
"DO_NOT_CANCEL" collection, and then later during the shutdown
sequence we make sure that the task that wraps this coro will NOT
be cancelled.
To make this work, we have to create ... | [
"Prevent",
"coro",
"from",
"being",
"cancelled",
"during",
"the",
"shutdown",
"sequence",
"."
] | 23c73318447f578a4a24845c5f43574ac7b414e4 | https://github.com/cjrh/aiorun/blob/23c73318447f578a4a24845c5f43574ac7b414e4/aiorun.py#L43-L117 |
10,028 | cjrh/aiorun | aiorun.py | run | def run(coro: 'Optional[Coroutine]' = None, *,
loop: Optional[AbstractEventLoop] = None,
shutdown_handler: Optional[Callable[[AbstractEventLoop], None]] = None,
executor_workers: int = 10,
executor: Optional[Executor] = None,
use_uvloop: bool = False) -> None:
"""
Start u... | python | def run(coro: 'Optional[Coroutine]' = None, *,
loop: Optional[AbstractEventLoop] = None,
shutdown_handler: Optional[Callable[[AbstractEventLoop], None]] = None,
executor_workers: int = 10,
executor: Optional[Executor] = None,
use_uvloop: bool = False) -> None:
"""
Start u... | [
"def",
"run",
"(",
"coro",
":",
"'Optional[Coroutine]'",
"=",
"None",
",",
"*",
",",
"loop",
":",
"Optional",
"[",
"AbstractEventLoop",
"]",
"=",
"None",
",",
"shutdown_handler",
":",
"Optional",
"[",
"Callable",
"[",
"[",
"AbstractEventLoop",
"]",
",",
"N... | Start up the event loop, and wait for a signal to shut down.
:param coro: Optionally supply a coroutine. The loop will still
run if missing. The loop will continue to run after the supplied
coroutine finishes. The supplied coroutine is typically
a "main" coroutine from which all other work ... | [
"Start",
"up",
"the",
"event",
"loop",
"and",
"wait",
"for",
"a",
"signal",
"to",
"shut",
"down",
"."
] | 23c73318447f578a4a24845c5f43574ac7b414e4 | https://github.com/cjrh/aiorun/blob/23c73318447f578a4a24845c5f43574ac7b414e4/aiorun.py#L120-L255 |
10,029 | emre/storm | storm/kommandr.py | prog.command | def command(self, *args, **kwargs):
"""Convenient decorator simply creates corresponding command"""
if len(args) == 1 and isinstance(args[0], collections.Callable):
return self._generate_command(args[0])
else:
def _command(func):
return self._generate_comm... | python | def command(self, *args, **kwargs):
"""Convenient decorator simply creates corresponding command"""
if len(args) == 1 and isinstance(args[0], collections.Callable):
return self._generate_command(args[0])
else:
def _command(func):
return self._generate_comm... | [
"def",
"command",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"len",
"(",
"args",
")",
"==",
"1",
"and",
"isinstance",
"(",
"args",
"[",
"0",
"]",
",",
"collections",
".",
"Callable",
")",
":",
"return",
"self",
".",
... | Convenient decorator simply creates corresponding command | [
"Convenient",
"decorator",
"simply",
"creates",
"corresponding",
"command"
] | c752defc1b718cfffbf0e0e15532fa1d7840bf6d | https://github.com/emre/storm/blob/c752defc1b718cfffbf0e0e15532fa1d7840bf6d/storm/kommandr.py#L96-L103 |
10,030 | emre/storm | storm/kommandr.py | prog._generate_command | def _generate_command(self, func, name=None, **kwargs):
"""Generates a command parser for given func.
:param func: func to generate related command parser
:param type: function
:param name: command name
:param type: str
:param **kwargs: keyword arguments those passed t... | python | def _generate_command(self, func, name=None, **kwargs):
"""Generates a command parser for given func.
:param func: func to generate related command parser
:param type: function
:param name: command name
:param type: str
:param **kwargs: keyword arguments those passed t... | [
"def",
"_generate_command",
"(",
"self",
",",
"func",
",",
"name",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"func_pointer",
"=",
"name",
"or",
"func",
".",
"__name__",
"storm_config",
"=",
"get_storm_config",
"(",
")",
"aliases",
",",
"additional_kw... | Generates a command parser for given func.
:param func: func to generate related command parser
:param type: function
:param name: command name
:param type: str
:param **kwargs: keyword arguments those passed through to
:py:class:``argparse.ArgumentPar... | [
"Generates",
"a",
"command",
"parser",
"for",
"given",
"func",
"."
] | c752defc1b718cfffbf0e0e15532fa1d7840bf6d | https://github.com/emre/storm/blob/c752defc1b718cfffbf0e0e15532fa1d7840bf6d/storm/kommandr.py#L121-L177 |
10,031 | emre/storm | storm/kommandr.py | prog.execute | def execute(self, arg_list):
"""Main function to parse and dispatch commands by given ``arg_list``
:param arg_list: all arguments provided by the command line
:param type: list
"""
arg_map = self.parser.parse_args(arg_list).__dict__
command = arg_map.pop(self._COMMAND_F... | python | def execute(self, arg_list):
"""Main function to parse and dispatch commands by given ``arg_list``
:param arg_list: all arguments provided by the command line
:param type: list
"""
arg_map = self.parser.parse_args(arg_list).__dict__
command = arg_map.pop(self._COMMAND_F... | [
"def",
"execute",
"(",
"self",
",",
"arg_list",
")",
":",
"arg_map",
"=",
"self",
".",
"parser",
".",
"parse_args",
"(",
"arg_list",
")",
".",
"__dict__",
"command",
"=",
"arg_map",
".",
"pop",
"(",
"self",
".",
"_COMMAND_FLAG",
")",
"return",
"command",... | Main function to parse and dispatch commands by given ``arg_list``
:param arg_list: all arguments provided by the command line
:param type: list | [
"Main",
"function",
"to",
"parse",
"and",
"dispatch",
"commands",
"by",
"given",
"arg_list"
] | c752defc1b718cfffbf0e0e15532fa1d7840bf6d | https://github.com/emre/storm/blob/c752defc1b718cfffbf0e0e15532fa1d7840bf6d/storm/kommandr.py#L179-L188 |
10,032 | emre/storm | storm/__main__.py | add | def add(name, connection_uri, id_file="", o=[], config=None):
"""
Adds a new entry to sshconfig.
"""
storm_ = get_storm_instance(config)
try:
# validate name
if '@' in name:
raise ValueError('invalid value: "@" cannot be used in name.')
user, host, port = parse... | python | def add(name, connection_uri, id_file="", o=[], config=None):
"""
Adds a new entry to sshconfig.
"""
storm_ = get_storm_instance(config)
try:
# validate name
if '@' in name:
raise ValueError('invalid value: "@" cannot be used in name.')
user, host, port = parse... | [
"def",
"add",
"(",
"name",
",",
"connection_uri",
",",
"id_file",
"=",
"\"\"",
",",
"o",
"=",
"[",
"]",
",",
"config",
"=",
"None",
")",
":",
"storm_",
"=",
"get_storm_instance",
"(",
"config",
")",
"try",
":",
"# validate name",
"if",
"'@'",
"in",
"... | Adds a new entry to sshconfig. | [
"Adds",
"a",
"new",
"entry",
"to",
"sshconfig",
"."
] | c752defc1b718cfffbf0e0e15532fa1d7840bf6d | https://github.com/emre/storm/blob/c752defc1b718cfffbf0e0e15532fa1d7840bf6d/storm/__main__.py#L34-L63 |
10,033 | emre/storm | storm/__main__.py | clone | def clone(name, clone_name, config=None):
"""
Clone an entry to the sshconfig.
"""
storm_ = get_storm_instance(config)
try:
# validate name
if '@' in name:
raise ValueError('invalid value: "@" cannot be used in name.')
storm_.clone_entry(name, clone_name)
... | python | def clone(name, clone_name, config=None):
"""
Clone an entry to the sshconfig.
"""
storm_ = get_storm_instance(config)
try:
# validate name
if '@' in name:
raise ValueError('invalid value: "@" cannot be used in name.')
storm_.clone_entry(name, clone_name)
... | [
"def",
"clone",
"(",
"name",
",",
"clone_name",
",",
"config",
"=",
"None",
")",
":",
"storm_",
"=",
"get_storm_instance",
"(",
"config",
")",
"try",
":",
"# validate name",
"if",
"'@'",
"in",
"name",
":",
"raise",
"ValueError",
"(",
"'invalid value: \"@\" c... | Clone an entry to the sshconfig. | [
"Clone",
"an",
"entry",
"to",
"the",
"sshconfig",
"."
] | c752defc1b718cfffbf0e0e15532fa1d7840bf6d | https://github.com/emre/storm/blob/c752defc1b718cfffbf0e0e15532fa1d7840bf6d/storm/__main__.py#L67-L90 |
10,034 | emre/storm | storm/__main__.py | move | def move(name, entry_name, config=None):
"""
Move an entry to the sshconfig.
"""
storm_ = get_storm_instance(config)
try:
if '@' in name:
raise ValueError('invalid value: "@" cannot be used in name.')
storm_.clone_entry(name, entry_name, keep_original=False)
p... | python | def move(name, entry_name, config=None):
"""
Move an entry to the sshconfig.
"""
storm_ = get_storm_instance(config)
try:
if '@' in name:
raise ValueError('invalid value: "@" cannot be used in name.')
storm_.clone_entry(name, entry_name, keep_original=False)
p... | [
"def",
"move",
"(",
"name",
",",
"entry_name",
",",
"config",
"=",
"None",
")",
":",
"storm_",
"=",
"get_storm_instance",
"(",
"config",
")",
"try",
":",
"if",
"'@'",
"in",
"name",
":",
"raise",
"ValueError",
"(",
"'invalid value: \"@\" cannot be used in name.... | Move an entry to the sshconfig. | [
"Move",
"an",
"entry",
"to",
"the",
"sshconfig",
"."
] | c752defc1b718cfffbf0e0e15532fa1d7840bf6d | https://github.com/emre/storm/blob/c752defc1b718cfffbf0e0e15532fa1d7840bf6d/storm/__main__.py#L93-L117 |
10,035 | emre/storm | storm/__main__.py | edit | def edit(name, connection_uri, id_file="", o=[], config=None):
"""
Edits the related entry in ssh config.
"""
storm_ = get_storm_instance(config)
try:
if ',' in name:
name = " ".join(name.split(","))
user, host, port = parse(
connection_uri,
user... | python | def edit(name, connection_uri, id_file="", o=[], config=None):
"""
Edits the related entry in ssh config.
"""
storm_ = get_storm_instance(config)
try:
if ',' in name:
name = " ".join(name.split(","))
user, host, port = parse(
connection_uri,
user... | [
"def",
"edit",
"(",
"name",
",",
"connection_uri",
",",
"id_file",
"=",
"\"\"",
",",
"o",
"=",
"[",
"]",
",",
"config",
"=",
"None",
")",
":",
"storm_",
"=",
"get_storm_instance",
"(",
"config",
")",
"try",
":",
"if",
"','",
"in",
"name",
":",
"nam... | Edits the related entry in ssh config. | [
"Edits",
"the",
"related",
"entry",
"in",
"ssh",
"config",
"."
] | c752defc1b718cfffbf0e0e15532fa1d7840bf6d | https://github.com/emre/storm/blob/c752defc1b718cfffbf0e0e15532fa1d7840bf6d/storm/__main__.py#L120-L143 |
10,036 | emre/storm | storm/__main__.py | update | def update(name, connection_uri="", id_file="", o=[], config=None):
"""
Enhanced version of the edit command featuring multiple
edits using regular expressions to match entries
"""
storm_ = get_storm_instance(config)
settings = {}
if id_file != "":
settings['identityfile'] = id_fil... | python | def update(name, connection_uri="", id_file="", o=[], config=None):
"""
Enhanced version of the edit command featuring multiple
edits using regular expressions to match entries
"""
storm_ = get_storm_instance(config)
settings = {}
if id_file != "":
settings['identityfile'] = id_fil... | [
"def",
"update",
"(",
"name",
",",
"connection_uri",
"=",
"\"\"",
",",
"id_file",
"=",
"\"\"",
",",
"o",
"=",
"[",
"]",
",",
"config",
"=",
"None",
")",
":",
"storm_",
"=",
"get_storm_instance",
"(",
"config",
")",
"settings",
"=",
"{",
"}",
"if",
... | Enhanced version of the edit command featuring multiple
edits using regular expressions to match entries | [
"Enhanced",
"version",
"of",
"the",
"edit",
"command",
"featuring",
"multiple",
"edits",
"using",
"regular",
"expressions",
"to",
"match",
"entries"
] | c752defc1b718cfffbf0e0e15532fa1d7840bf6d | https://github.com/emre/storm/blob/c752defc1b718cfffbf0e0e15532fa1d7840bf6d/storm/__main__.py#L146-L169 |
10,037 | emre/storm | storm/__main__.py | delete | def delete(name, config=None):
"""
Deletes a single host.
"""
storm_ = get_storm_instance(config)
try:
storm_.delete_entry(name)
print(
get_formatted_message(
'hostname "{0}" deleted successfully.'.format(name),
'success')
)
except... | python | def delete(name, config=None):
"""
Deletes a single host.
"""
storm_ = get_storm_instance(config)
try:
storm_.delete_entry(name)
print(
get_formatted_message(
'hostname "{0}" deleted successfully.'.format(name),
'success')
)
except... | [
"def",
"delete",
"(",
"name",
",",
"config",
"=",
"None",
")",
":",
"storm_",
"=",
"get_storm_instance",
"(",
"config",
")",
"try",
":",
"storm_",
".",
"delete_entry",
"(",
"name",
")",
"print",
"(",
"get_formatted_message",
"(",
"'hostname \"{0}\" deleted suc... | Deletes a single host. | [
"Deletes",
"a",
"single",
"host",
"."
] | c752defc1b718cfffbf0e0e15532fa1d7840bf6d | https://github.com/emre/storm/blob/c752defc1b718cfffbf0e0e15532fa1d7840bf6d/storm/__main__.py#L172-L187 |
10,038 | emre/storm | storm/__main__.py | list | def list(config=None):
"""
Lists all hosts from ssh config.
"""
storm_ = get_storm_instance(config)
try:
result = colored('Listing entries:', 'white', attrs=["bold", ]) + "\n\n"
result_stack = ""
for host in storm_.list_entries(True):
if host.get("type") == 'ent... | python | def list(config=None):
"""
Lists all hosts from ssh config.
"""
storm_ = get_storm_instance(config)
try:
result = colored('Listing entries:', 'white', attrs=["bold", ]) + "\n\n"
result_stack = ""
for host in storm_.list_entries(True):
if host.get("type") == 'ent... | [
"def",
"list",
"(",
"config",
"=",
"None",
")",
":",
"storm_",
"=",
"get_storm_instance",
"(",
"config",
")",
"try",
":",
"result",
"=",
"colored",
"(",
"'Listing entries:'",
",",
"'white'",
",",
"attrs",
"=",
"[",
"\"bold\"",
",",
"]",
")",
"+",
"\"\\... | Lists all hosts from ssh config. | [
"Lists",
"all",
"hosts",
"from",
"ssh",
"config",
"."
] | c752defc1b718cfffbf0e0e15532fa1d7840bf6d | https://github.com/emre/storm/blob/c752defc1b718cfffbf0e0e15532fa1d7840bf6d/storm/__main__.py#L190-L258 |
10,039 | emre/storm | storm/__main__.py | search | def search(search_text, config=None):
"""
Searches entries by given search text.
"""
storm_ = get_storm_instance(config)
try:
results = storm_.search_host(search_text)
if len(results) == 0:
print ('no results found.')
if len(results) > 0:
message = '... | python | def search(search_text, config=None):
"""
Searches entries by given search text.
"""
storm_ = get_storm_instance(config)
try:
results = storm_.search_host(search_text)
if len(results) == 0:
print ('no results found.')
if len(results) > 0:
message = '... | [
"def",
"search",
"(",
"search_text",
",",
"config",
"=",
"None",
")",
":",
"storm_",
"=",
"get_storm_instance",
"(",
"config",
")",
"try",
":",
"results",
"=",
"storm_",
".",
"search_host",
"(",
"search_text",
")",
"if",
"len",
"(",
"results",
")",
"==",... | Searches entries by given search text. | [
"Searches",
"entries",
"by",
"given",
"search",
"text",
"."
] | c752defc1b718cfffbf0e0e15532fa1d7840bf6d | https://github.com/emre/storm/blob/c752defc1b718cfffbf0e0e15532fa1d7840bf6d/storm/__main__.py#L261-L278 |
10,040 | emre/storm | storm/__main__.py | delete_all | def delete_all(config=None):
"""
Deletes all hosts from ssh config.
"""
storm_ = get_storm_instance(config)
try:
storm_.delete_all_entries()
print(get_formatted_message('all entries deleted.', 'success'))
except Exception as error:
print(get_formatted_message(str(error),... | python | def delete_all(config=None):
"""
Deletes all hosts from ssh config.
"""
storm_ = get_storm_instance(config)
try:
storm_.delete_all_entries()
print(get_formatted_message('all entries deleted.', 'success'))
except Exception as error:
print(get_formatted_message(str(error),... | [
"def",
"delete_all",
"(",
"config",
"=",
"None",
")",
":",
"storm_",
"=",
"get_storm_instance",
"(",
"config",
")",
"try",
":",
"storm_",
".",
"delete_all_entries",
"(",
")",
"print",
"(",
"get_formatted_message",
"(",
"'all entries deleted.'",
",",
"'success'",... | Deletes all hosts from ssh config. | [
"Deletes",
"all",
"hosts",
"from",
"ssh",
"config",
"."
] | c752defc1b718cfffbf0e0e15532fa1d7840bf6d | https://github.com/emre/storm/blob/c752defc1b718cfffbf0e0e15532fa1d7840bf6d/storm/__main__.py#L281-L292 |
10,041 | emre/storm | storm/__main__.py | backup | def backup(target_file, config=None):
"""
Backups the main ssh configuration into target file.
"""
storm_ = get_storm_instance(config)
try:
storm_.backup(target_file)
except Exception as error:
print(get_formatted_message(str(error), 'error'), file=sys.stderr)
sys.exit(1) | python | def backup(target_file, config=None):
"""
Backups the main ssh configuration into target file.
"""
storm_ = get_storm_instance(config)
try:
storm_.backup(target_file)
except Exception as error:
print(get_formatted_message(str(error), 'error'), file=sys.stderr)
sys.exit(1) | [
"def",
"backup",
"(",
"target_file",
",",
"config",
"=",
"None",
")",
":",
"storm_",
"=",
"get_storm_instance",
"(",
"config",
")",
"try",
":",
"storm_",
".",
"backup",
"(",
"target_file",
")",
"except",
"Exception",
"as",
"error",
":",
"print",
"(",
"ge... | Backups the main ssh configuration into target file. | [
"Backups",
"the",
"main",
"ssh",
"configuration",
"into",
"target",
"file",
"."
] | c752defc1b718cfffbf0e0e15532fa1d7840bf6d | https://github.com/emre/storm/blob/c752defc1b718cfffbf0e0e15532fa1d7840bf6d/storm/__main__.py#L295-L304 |
10,042 | emre/storm | storm/__main__.py | web | def web(port, debug=False, theme="modern", ssh_config=None):
"""Starts the web UI."""
from storm import web as _web
_web.run(port, debug, theme, ssh_config) | python | def web(port, debug=False, theme="modern", ssh_config=None):
"""Starts the web UI."""
from storm import web as _web
_web.run(port, debug, theme, ssh_config) | [
"def",
"web",
"(",
"port",
",",
"debug",
"=",
"False",
",",
"theme",
"=",
"\"modern\"",
",",
"ssh_config",
"=",
"None",
")",
":",
"from",
"storm",
"import",
"web",
"as",
"_web",
"_web",
".",
"run",
"(",
"port",
",",
"debug",
",",
"theme",
",",
"ssh... | Starts the web UI. | [
"Starts",
"the",
"web",
"UI",
"."
] | c752defc1b718cfffbf0e0e15532fa1d7840bf6d | https://github.com/emre/storm/blob/c752defc1b718cfffbf0e0e15532fa1d7840bf6d/storm/__main__.py#L310-L313 |
10,043 | diging/tethne | tethne/writers/collection.py | _strip_list_attributes | def _strip_list_attributes(graph_):
"""Converts lists attributes to strings for all nodes and edges in G."""
for n_ in graph_.nodes(data=True):
for k,v in n_[1].iteritems():
if type(v) is list:
graph_.node[n_[0]][k] = unicode(v)
for e_ in graph_.edges(data=True):
... | python | def _strip_list_attributes(graph_):
"""Converts lists attributes to strings for all nodes and edges in G."""
for n_ in graph_.nodes(data=True):
for k,v in n_[1].iteritems():
if type(v) is list:
graph_.node[n_[0]][k] = unicode(v)
for e_ in graph_.edges(data=True):
... | [
"def",
"_strip_list_attributes",
"(",
"graph_",
")",
":",
"for",
"n_",
"in",
"graph_",
".",
"nodes",
"(",
"data",
"=",
"True",
")",
":",
"for",
"k",
",",
"v",
"in",
"n_",
"[",
"1",
"]",
".",
"iteritems",
"(",
")",
":",
"if",
"type",
"(",
"v",
"... | Converts lists attributes to strings for all nodes and edges in G. | [
"Converts",
"lists",
"attributes",
"to",
"strings",
"for",
"all",
"nodes",
"and",
"edges",
"in",
"G",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/writers/collection.py#L189-L200 |
10,044 | diging/tethne | tethne/writers/collection.py | _safe_type | def _safe_type(value):
"""Converts Python type names to XGMML-safe type names."""
if type(value) is str: dtype = 'string'
if type(value) is unicode: dtype = 'string'
if type(value) is int: dtype = 'integer'
if type(value) is float: dtype = 'real'
return dtype | python | def _safe_type(value):
"""Converts Python type names to XGMML-safe type names."""
if type(value) is str: dtype = 'string'
if type(value) is unicode: dtype = 'string'
if type(value) is int: dtype = 'integer'
if type(value) is float: dtype = 'real'
return dtype | [
"def",
"_safe_type",
"(",
"value",
")",
":",
"if",
"type",
"(",
"value",
")",
"is",
"str",
":",
"dtype",
"=",
"'string'",
"if",
"type",
"(",
"value",
")",
"is",
"unicode",
":",
"dtype",
"=",
"'string'",
"if",
"type",
"(",
"value",
")",
"is",
"int",... | Converts Python type names to XGMML-safe type names. | [
"Converts",
"Python",
"type",
"names",
"to",
"XGMML",
"-",
"safe",
"type",
"names",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/writers/collection.py#L202-L210 |
10,045 | diging/tethne | tethne/readers/wos.py | read | def read(path, corpus=True, index_by='wosid', streaming=False, parse_only=None,
corpus_class=Corpus, **kwargs):
"""
Parse one or more WoS field-tagged data files.
Examples
--------
.. code-block:: python
>>> from tethne.readers import wos
>>> corpus = wos.read("/path/to/some... | python | def read(path, corpus=True, index_by='wosid', streaming=False, parse_only=None,
corpus_class=Corpus, **kwargs):
"""
Parse one or more WoS field-tagged data files.
Examples
--------
.. code-block:: python
>>> from tethne.readers import wos
>>> corpus = wos.read("/path/to/some... | [
"def",
"read",
"(",
"path",
",",
"corpus",
"=",
"True",
",",
"index_by",
"=",
"'wosid'",
",",
"streaming",
"=",
"False",
",",
"parse_only",
"=",
"None",
",",
"corpus_class",
"=",
"Corpus",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"os",
".",
... | Parse one or more WoS field-tagged data files.
Examples
--------
.. code-block:: python
>>> from tethne.readers import wos
>>> corpus = wos.read("/path/to/some/wos/data")
>>> corpus
<tethne.classes.corpus.Corpus object at 0x10057c2d0>
Parameters
----------
path : s... | [
"Parse",
"one",
"or",
"more",
"WoS",
"field",
"-",
"tagged",
"data",
"files",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L350-L401 |
10,046 | diging/tethne | tethne/readers/wos.py | WoSParser.parse_author | def parse_author(self, value):
"""
Attempts to split an author name into last and first parts.
"""
tokens = tuple([t.upper().strip() for t in value.split(',')])
if len(tokens) == 1:
tokens = value.split(' ')
if len(tokens) > 0:
if len(tokens) > 1:
... | python | def parse_author(self, value):
"""
Attempts to split an author name into last and first parts.
"""
tokens = tuple([t.upper().strip() for t in value.split(',')])
if len(tokens) == 1:
tokens = value.split(' ')
if len(tokens) > 0:
if len(tokens) > 1:
... | [
"def",
"parse_author",
"(",
"self",
",",
"value",
")",
":",
"tokens",
"=",
"tuple",
"(",
"[",
"t",
".",
"upper",
"(",
")",
".",
"strip",
"(",
")",
"for",
"t",
"in",
"value",
".",
"split",
"(",
"','",
")",
"]",
")",
"if",
"len",
"(",
"tokens",
... | Attempts to split an author name into last and first parts. | [
"Attempts",
"to",
"split",
"an",
"author",
"name",
"into",
"last",
"and",
"first",
"parts",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L112-L129 |
10,047 | diging/tethne | tethne/readers/wos.py | WoSParser.handle_CR | def handle_CR(self, value):
"""
Parses cited references.
"""
citation = self.entry_class()
value = strip_tags(value)
# First-author name and publication date.
ptn = '([\w\s\W]+),\s([0-9]{4}),\s([\w\s]+)'
ny_match = re.match(ptn, value, flags=re.U)
... | python | def handle_CR(self, value):
"""
Parses cited references.
"""
citation = self.entry_class()
value = strip_tags(value)
# First-author name and publication date.
ptn = '([\w\s\W]+),\s([0-9]{4}),\s([\w\s]+)'
ny_match = re.match(ptn, value, flags=re.U)
... | [
"def",
"handle_CR",
"(",
"self",
",",
"value",
")",
":",
"citation",
"=",
"self",
".",
"entry_class",
"(",
")",
"value",
"=",
"strip_tags",
"(",
"value",
")",
"# First-author name and publication date.",
"ptn",
"=",
"'([\\w\\s\\W]+),\\s([0-9]{4}),\\s([\\w\\s]+)'",
"... | Parses cited references. | [
"Parses",
"cited",
"references",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L157-L227 |
10,048 | diging/tethne | tethne/readers/wos.py | WoSParser.postprocess_WC | def postprocess_WC(self, entry):
"""
Parse WC keywords.
Subject keywords are usually semicolon-delimited.
"""
if type(entry.WC) not in [str, unicode]:
WC= u' '.join([unicode(k) for k in entry.WC])
else:
WC= entry.WC
entry.WC= [k.strip().u... | python | def postprocess_WC(self, entry):
"""
Parse WC keywords.
Subject keywords are usually semicolon-delimited.
"""
if type(entry.WC) not in [str, unicode]:
WC= u' '.join([unicode(k) for k in entry.WC])
else:
WC= entry.WC
entry.WC= [k.strip().u... | [
"def",
"postprocess_WC",
"(",
"self",
",",
"entry",
")",
":",
"if",
"type",
"(",
"entry",
".",
"WC",
")",
"not",
"in",
"[",
"str",
",",
"unicode",
"]",
":",
"WC",
"=",
"u' '",
".",
"join",
"(",
"[",
"unicode",
"(",
"k",
")",
"for",
"k",
"in",
... | Parse WC keywords.
Subject keywords are usually semicolon-delimited. | [
"Parse",
"WC",
"keywords",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L229-L240 |
10,049 | diging/tethne | tethne/readers/wos.py | WoSParser.postprocess_subject | def postprocess_subject(self, entry):
"""
Parse subject keywords.
Subject keywords are usually semicolon-delimited.
"""
if type(entry.subject) not in [str, unicode]:
subject = u' '.join([unicode(k) for k in entry.subject])
else:
subject = entry.s... | python | def postprocess_subject(self, entry):
"""
Parse subject keywords.
Subject keywords are usually semicolon-delimited.
"""
if type(entry.subject) not in [str, unicode]:
subject = u' '.join([unicode(k) for k in entry.subject])
else:
subject = entry.s... | [
"def",
"postprocess_subject",
"(",
"self",
",",
"entry",
")",
":",
"if",
"type",
"(",
"entry",
".",
"subject",
")",
"not",
"in",
"[",
"str",
",",
"unicode",
"]",
":",
"subject",
"=",
"u' '",
".",
"join",
"(",
"[",
"unicode",
"(",
"k",
")",
"for",
... | Parse subject keywords.
Subject keywords are usually semicolon-delimited. | [
"Parse",
"subject",
"keywords",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L242-L253 |
10,050 | diging/tethne | tethne/readers/wos.py | WoSParser.postprocess_authorKeywords | def postprocess_authorKeywords(self, entry):
"""
Parse author keywords.
Author keywords are usually semicolon-delimited.
"""
if type(entry.authorKeywords) not in [str, unicode]:
aK = u' '.join([unicode(k) for k in entry.authorKeywords])
else:
aK ... | python | def postprocess_authorKeywords(self, entry):
"""
Parse author keywords.
Author keywords are usually semicolon-delimited.
"""
if type(entry.authorKeywords) not in [str, unicode]:
aK = u' '.join([unicode(k) for k in entry.authorKeywords])
else:
aK ... | [
"def",
"postprocess_authorKeywords",
"(",
"self",
",",
"entry",
")",
":",
"if",
"type",
"(",
"entry",
".",
"authorKeywords",
")",
"not",
"in",
"[",
"str",
",",
"unicode",
"]",
":",
"aK",
"=",
"u' '",
".",
"join",
"(",
"[",
"unicode",
"(",
"k",
")",
... | Parse author keywords.
Author keywords are usually semicolon-delimited. | [
"Parse",
"author",
"keywords",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L255-L266 |
10,051 | diging/tethne | tethne/readers/wos.py | WoSParser.postprocess_keywordsPlus | def postprocess_keywordsPlus(self, entry):
"""
Parse WoS "Keyword Plus" keywords.
Keyword Plus keywords are usually semicolon-delimited.
"""
if type(entry.keywordsPlus) in [str, unicode]:
entry.keywordsPlus = [k.strip().upper() for k
... | python | def postprocess_keywordsPlus(self, entry):
"""
Parse WoS "Keyword Plus" keywords.
Keyword Plus keywords are usually semicolon-delimited.
"""
if type(entry.keywordsPlus) in [str, unicode]:
entry.keywordsPlus = [k.strip().upper() for k
... | [
"def",
"postprocess_keywordsPlus",
"(",
"self",
",",
"entry",
")",
":",
"if",
"type",
"(",
"entry",
".",
"keywordsPlus",
")",
"in",
"[",
"str",
",",
"unicode",
"]",
":",
"entry",
".",
"keywordsPlus",
"=",
"[",
"k",
".",
"strip",
"(",
")",
".",
"upper... | Parse WoS "Keyword Plus" keywords.
Keyword Plus keywords are usually semicolon-delimited. | [
"Parse",
"WoS",
"Keyword",
"Plus",
"keywords",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L268-L277 |
10,052 | diging/tethne | tethne/readers/wos.py | WoSParser.postprocess_funding | def postprocess_funding(self, entry):
"""
Separates funding agency from grant numbers.
"""
if type(entry.funding) not in [str, unicode]:
return
sources = [fu.strip() for fu in entry.funding.split(';')]
sources_processed = []
for source in sources:
... | python | def postprocess_funding(self, entry):
"""
Separates funding agency from grant numbers.
"""
if type(entry.funding) not in [str, unicode]:
return
sources = [fu.strip() for fu in entry.funding.split(';')]
sources_processed = []
for source in sources:
... | [
"def",
"postprocess_funding",
"(",
"self",
",",
"entry",
")",
":",
"if",
"type",
"(",
"entry",
".",
"funding",
")",
"not",
"in",
"[",
"str",
",",
"unicode",
"]",
":",
"return",
"sources",
"=",
"[",
"fu",
".",
"strip",
"(",
")",
"for",
"fu",
"in",
... | Separates funding agency from grant numbers. | [
"Separates",
"funding",
"agency",
"from",
"grant",
"numbers",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L279-L296 |
10,053 | diging/tethne | tethne/readers/wos.py | WoSParser.postprocess_authors_full | def postprocess_authors_full(self, entry):
"""
If only a single author was found, ensure that ``authors_full`` is
nonetheless a list.
"""
if type(entry.authors_full) is not list:
entry.authors_full = [entry.authors_full] | python | def postprocess_authors_full(self, entry):
"""
If only a single author was found, ensure that ``authors_full`` is
nonetheless a list.
"""
if type(entry.authors_full) is not list:
entry.authors_full = [entry.authors_full] | [
"def",
"postprocess_authors_full",
"(",
"self",
",",
"entry",
")",
":",
"if",
"type",
"(",
"entry",
".",
"authors_full",
")",
"is",
"not",
"list",
":",
"entry",
".",
"authors_full",
"=",
"[",
"entry",
".",
"authors_full",
"]"
] | If only a single author was found, ensure that ``authors_full`` is
nonetheless a list. | [
"If",
"only",
"a",
"single",
"author",
"was",
"found",
"ensure",
"that",
"authors_full",
"is",
"nonetheless",
"a",
"list",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L298-L304 |
10,054 | diging/tethne | tethne/readers/wos.py | WoSParser.postprocess_authors_init | def postprocess_authors_init(self, entry):
"""
If only a single author was found, ensure that ``authors_init`` is
nonetheless a list.
"""
if type(entry.authors_init) is not list:
entry.authors_init = [entry.authors_init] | python | def postprocess_authors_init(self, entry):
"""
If only a single author was found, ensure that ``authors_init`` is
nonetheless a list.
"""
if type(entry.authors_init) is not list:
entry.authors_init = [entry.authors_init] | [
"def",
"postprocess_authors_init",
"(",
"self",
",",
"entry",
")",
":",
"if",
"type",
"(",
"entry",
".",
"authors_init",
")",
"is",
"not",
"list",
":",
"entry",
".",
"authors_init",
"=",
"[",
"entry",
".",
"authors_init",
"]"
] | If only a single author was found, ensure that ``authors_init`` is
nonetheless a list. | [
"If",
"only",
"a",
"single",
"author",
"was",
"found",
"ensure",
"that",
"authors_init",
"is",
"nonetheless",
"a",
"list",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L306-L312 |
10,055 | diging/tethne | tethne/readers/wos.py | WoSParser.postprocess_citedReferences | def postprocess_citedReferences(self, entry):
"""
If only a single cited reference was found, ensure that
``citedReferences`` is nonetheless a list.
"""
if type(entry.citedReferences) is not list:
entry.citedReferences = [entry.citedReferences] | python | def postprocess_citedReferences(self, entry):
"""
If only a single cited reference was found, ensure that
``citedReferences`` is nonetheless a list.
"""
if type(entry.citedReferences) is not list:
entry.citedReferences = [entry.citedReferences] | [
"def",
"postprocess_citedReferences",
"(",
"self",
",",
"entry",
")",
":",
"if",
"type",
"(",
"entry",
".",
"citedReferences",
")",
"is",
"not",
"list",
":",
"entry",
".",
"citedReferences",
"=",
"[",
"entry",
".",
"citedReferences",
"]"
] | If only a single cited reference was found, ensure that
``citedReferences`` is nonetheless a list. | [
"If",
"only",
"a",
"single",
"cited",
"reference",
"was",
"found",
"ensure",
"that",
"citedReferences",
"is",
"nonetheless",
"a",
"list",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/wos.py#L314-L320 |
10,056 | diging/tethne | tethne/plot/__init__.py | plot_burstness | def plot_burstness(corpus, B, **kwargs):
"""
Generate a figure depicting burstness profiles for ``feature``.
Parameters
----------
B
Returns
-------
fig : :class:`matplotlib.figure.Figure`
Examples
--------
.. code-block:: python
>>> from tethne.analyze.corpus imp... | python | def plot_burstness(corpus, B, **kwargs):
"""
Generate a figure depicting burstness profiles for ``feature``.
Parameters
----------
B
Returns
-------
fig : :class:`matplotlib.figure.Figure`
Examples
--------
.. code-block:: python
>>> from tethne.analyze.corpus imp... | [
"def",
"plot_burstness",
"(",
"corpus",
",",
"B",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"import",
"matplotlib",
".",
"pyplot",
"as",
"plt",
"import",
"matplotlib",
".",
"patches",
"as",
"mpatches",
"except",
"ImportError",
":",
"raise",
"RuntimeEr... | Generate a figure depicting burstness profiles for ``feature``.
Parameters
----------
B
Returns
-------
fig : :class:`matplotlib.figure.Figure`
Examples
--------
.. code-block:: python
>>> from tethne.analyze.corpus import burstness
>>> fig = plot_burstness(corpus,... | [
"Generate",
"a",
"figure",
"depicting",
"burstness",
"profiles",
"for",
"feature",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/plot/__init__.py#L11-L97 |
10,057 | diging/tethne | tethne/networks/helpers.py | simplify_multigraph | def simplify_multigraph(multigraph, time=False):
"""
Simplifies a graph by condensing multiple edges between the same node pair
into a single edge, with a weight attribute equal to the number of edges.
Parameters
----------
graph : networkx.MultiGraph
E.g. a coauthorship graph.
time... | python | def simplify_multigraph(multigraph, time=False):
"""
Simplifies a graph by condensing multiple edges between the same node pair
into a single edge, with a weight attribute equal to the number of edges.
Parameters
----------
graph : networkx.MultiGraph
E.g. a coauthorship graph.
time... | [
"def",
"simplify_multigraph",
"(",
"multigraph",
",",
"time",
"=",
"False",
")",
":",
"graph",
"=",
"nx",
".",
"Graph",
"(",
")",
"for",
"node",
"in",
"multigraph",
".",
"nodes",
"(",
"data",
"=",
"True",
")",
":",
"u",
"=",
"node",
"[",
"0",
"]",
... | Simplifies a graph by condensing multiple edges between the same node pair
into a single edge, with a weight attribute equal to the number of edges.
Parameters
----------
graph : networkx.MultiGraph
E.g. a coauthorship graph.
time : bool
If True, will generate 'start' and 'end' attr... | [
"Simplifies",
"a",
"graph",
"by",
"condensing",
"multiple",
"edges",
"between",
"the",
"same",
"node",
"pair",
"into",
"a",
"single",
"edge",
"with",
"a",
"weight",
"attribute",
"equal",
"to",
"the",
"number",
"of",
"edges",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/networks/helpers.py#L28-L81 |
10,058 | diging/tethne | tethne/networks/helpers.py | citation_count | def citation_count(papers, key='ayjid', verbose=False):
"""
Generates citation counts for all of the papers cited by papers.
Parameters
----------
papers : list
A list of :class:`.Paper` instances.
key : str
Property to use as node key. Default is 'ayjid' (recommended).
verb... | python | def citation_count(papers, key='ayjid', verbose=False):
"""
Generates citation counts for all of the papers cited by papers.
Parameters
----------
papers : list
A list of :class:`.Paper` instances.
key : str
Property to use as node key. Default is 'ayjid' (recommended).
verb... | [
"def",
"citation_count",
"(",
"papers",
",",
"key",
"=",
"'ayjid'",
",",
"verbose",
"=",
"False",
")",
":",
"if",
"verbose",
":",
"print",
"\"Generating citation counts for \"",
"+",
"unicode",
"(",
"len",
"(",
"papers",
")",
")",
"+",
"\" papers...\"",
"cou... | Generates citation counts for all of the papers cited by papers.
Parameters
----------
papers : list
A list of :class:`.Paper` instances.
key : str
Property to use as node key. Default is 'ayjid' (recommended).
verbose : bool
If True, prints status messages.
Returns
... | [
"Generates",
"citation",
"counts",
"for",
"all",
"of",
"the",
"papers",
"cited",
"by",
"papers",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/networks/helpers.py#L83-L111 |
10,059 | diging/tethne | tethne/analyze/collection.py | connected | def connected(G, method_name, **kwargs):
"""
Performs analysis methods from networkx.connected on each graph in the
collection.
Parameters
----------
G : :class:`.GraphCollection`
The :class:`.GraphCollection` to analyze. The specified method will be
applied to each graph in ``G... | python | def connected(G, method_name, **kwargs):
"""
Performs analysis methods from networkx.connected on each graph in the
collection.
Parameters
----------
G : :class:`.GraphCollection`
The :class:`.GraphCollection` to analyze. The specified method will be
applied to each graph in ``G... | [
"def",
"connected",
"(",
"G",
",",
"method_name",
",",
"*",
"*",
"kwargs",
")",
":",
"warnings",
".",
"warn",
"(",
"\"To be removed in 0.8. Use GraphCollection.analyze instead.\"",
",",
"DeprecationWarning",
")",
"return",
"G",
".",
"analyze",
"(",
"[",
"'connecte... | Performs analysis methods from networkx.connected on each graph in the
collection.
Parameters
----------
G : :class:`.GraphCollection`
The :class:`.GraphCollection` to analyze. The specified method will be
applied to each graph in ``G``.
method : string
Name of method in net... | [
"Performs",
"analysis",
"methods",
"from",
"networkx",
".",
"connected",
"on",
"each",
"graph",
"in",
"the",
"collection",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/analyze/collection.py#L72-L101 |
10,060 | diging/tethne | tethne/analyze/collection.py | attachment_probability | def attachment_probability(G):
"""
Calculates the observed attachment probability for each node at each
time-step.
Attachment probability is calculated based on the observed new edges in the
next time-step. So if a node acquires new edges at time t, this will accrue
to the node's attac... | python | def attachment_probability(G):
"""
Calculates the observed attachment probability for each node at each
time-step.
Attachment probability is calculated based on the observed new edges in the
next time-step. So if a node acquires new edges at time t, this will accrue
to the node's attac... | [
"def",
"attachment_probability",
"(",
"G",
")",
":",
"warnings",
".",
"warn",
"(",
"\"Removed in 0.8. Too domain-specific.\"",
")",
"probs",
"=",
"{",
"}",
"G_",
"=",
"None",
"k_",
"=",
"None",
"for",
"k",
",",
"g",
"in",
"G",
".",
"graphs",
".",
"iterit... | Calculates the observed attachment probability for each node at each
time-step.
Attachment probability is calculated based on the observed new edges in the
next time-step. So if a node acquires new edges at time t, this will accrue
to the node's attachment probability at time t-1. Thus at a gi... | [
"Calculates",
"the",
"observed",
"attachment",
"probability",
"for",
"each",
"node",
"at",
"each",
"time",
"-",
"step",
".",
"Attachment",
"probability",
"is",
"calculated",
"based",
"on",
"the",
"observed",
"new",
"edges",
"in",
"the",
"next",
"time",
"-",
... | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/analyze/collection.py#L104-L166 |
10,061 | diging/tethne | tethne/analyze/graph.py | global_closeness_centrality | def global_closeness_centrality(g, node=None, normalize=True):
"""
Calculates global closeness centrality for one or all nodes in the network.
See :func:`.node_global_closeness_centrality` for more information.
Parameters
----------
g : networkx.Graph
normalize : boolean
If True, n... | python | def global_closeness_centrality(g, node=None, normalize=True):
"""
Calculates global closeness centrality for one or all nodes in the network.
See :func:`.node_global_closeness_centrality` for more information.
Parameters
----------
g : networkx.Graph
normalize : boolean
If True, n... | [
"def",
"global_closeness_centrality",
"(",
"g",
",",
"node",
"=",
"None",
",",
"normalize",
"=",
"True",
")",
":",
"if",
"not",
"node",
":",
"C",
"=",
"{",
"}",
"for",
"node",
"in",
"g",
".",
"nodes",
"(",
")",
":",
"C",
"[",
"node",
"]",
"=",
... | Calculates global closeness centrality for one or all nodes in the network.
See :func:`.node_global_closeness_centrality` for more information.
Parameters
----------
g : networkx.Graph
normalize : boolean
If True, normalizes centrality based on the average shortest path
length. Def... | [
"Calculates",
"global",
"closeness",
"centrality",
"for",
"one",
"or",
"all",
"nodes",
"in",
"the",
"network",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/analyze/graph.py#L13-L49 |
10,062 | diging/tethne | tethne/readers/dfr.py | ngrams | def ngrams(path, elem, ignore_hash=True):
"""
Yields N-grams from a JSTOR DfR dataset.
Parameters
----------
path : string
Path to unzipped JSTOR DfR folder containing N-grams.
elem : string
Name of subdirectory containing N-grams. (e.g. 'bigrams').
ignore_hash : bool
... | python | def ngrams(path, elem, ignore_hash=True):
"""
Yields N-grams from a JSTOR DfR dataset.
Parameters
----------
path : string
Path to unzipped JSTOR DfR folder containing N-grams.
elem : string
Name of subdirectory containing N-grams. (e.g. 'bigrams').
ignore_hash : bool
... | [
"def",
"ngrams",
"(",
"path",
",",
"elem",
",",
"ignore_hash",
"=",
"True",
")",
":",
"grams",
"=",
"GramGenerator",
"(",
"path",
",",
"elem",
",",
"ignore_hash",
"=",
"ignore_hash",
")",
"return",
"FeatureSet",
"(",
"{",
"k",
":",
"Feature",
"(",
"f",... | Yields N-grams from a JSTOR DfR dataset.
Parameters
----------
path : string
Path to unzipped JSTOR DfR folder containing N-grams.
elem : string
Name of subdirectory containing N-grams. (e.g. 'bigrams').
ignore_hash : bool
If True, will exclude all N-grams that contain the h... | [
"Yields",
"N",
"-",
"grams",
"from",
"a",
"JSTOR",
"DfR",
"dataset",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/dfr.py#L294-L314 |
10,063 | diging/tethne | tethne/readers/dfr.py | tokenize | def tokenize(ngrams, min_tf=2, min_df=2, min_len=3, apply_stoplist=False):
"""
Builds a vocabulary, and replaces words with vocab indices.
Parameters
----------
ngrams : dict
Keys are paper DOIs, values are lists of (Ngram, frequency) tuples.
apply_stoplist : bool
If True, will ... | python | def tokenize(ngrams, min_tf=2, min_df=2, min_len=3, apply_stoplist=False):
"""
Builds a vocabulary, and replaces words with vocab indices.
Parameters
----------
ngrams : dict
Keys are paper DOIs, values are lists of (Ngram, frequency) tuples.
apply_stoplist : bool
If True, will ... | [
"def",
"tokenize",
"(",
"ngrams",
",",
"min_tf",
"=",
"2",
",",
"min_df",
"=",
"2",
",",
"min_len",
"=",
"3",
",",
"apply_stoplist",
"=",
"False",
")",
":",
"vocab",
"=",
"{",
"}",
"vocab_",
"=",
"{",
"}",
"word_tf",
"=",
"Counter",
"(",
")",
"wo... | Builds a vocabulary, and replaces words with vocab indices.
Parameters
----------
ngrams : dict
Keys are paper DOIs, values are lists of (Ngram, frequency) tuples.
apply_stoplist : bool
If True, will exclude all N-grams that contain words in the NLTK
stoplist.
Returns
-... | [
"Builds",
"a",
"vocabulary",
"and",
"replaces",
"words",
"with",
"vocab",
"indices",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/dfr.py#L317-L390 |
10,064 | diging/tethne | tethne/readers/dfr.py | _handle_pagerange | def _handle_pagerange(pagerange):
"""
Yields start and end pages from DfR pagerange field.
Parameters
----------
pagerange : str or unicode
DfR-style pagerange, e.g. "pp. 435-444".
Returns
-------
start : str
Start page.
end : str
End page.
"""
try:... | python | def _handle_pagerange(pagerange):
"""
Yields start and end pages from DfR pagerange field.
Parameters
----------
pagerange : str or unicode
DfR-style pagerange, e.g. "pp. 435-444".
Returns
-------
start : str
Start page.
end : str
End page.
"""
try:... | [
"def",
"_handle_pagerange",
"(",
"pagerange",
")",
":",
"try",
":",
"pr",
"=",
"re",
".",
"compile",
"(",
"\"pp\\.\\s([0-9]+)\\-([0-9]+)\"",
")",
"start",
",",
"end",
"=",
"re",
".",
"findall",
"(",
"pr",
",",
"pagerange",
")",
"[",
"0",
"]",
"except",
... | Yields start and end pages from DfR pagerange field.
Parameters
----------
pagerange : str or unicode
DfR-style pagerange, e.g. "pp. 435-444".
Returns
-------
start : str
Start page.
end : str
End page. | [
"Yields",
"start",
"and",
"end",
"pages",
"from",
"DfR",
"pagerange",
"field",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/dfr.py#L430-L453 |
10,065 | diging/tethne | tethne/readers/dfr.py | _handle_authors | def _handle_authors(authors):
"""
Yields aulast and auinit lists from value of authors node.
Parameters
----------
authors : list, str, or unicode
Value or values of 'author' element in DfR XML.
Returns
-------
aulast : list
A list of author surnames (string).
auini... | python | def _handle_authors(authors):
"""
Yields aulast and auinit lists from value of authors node.
Parameters
----------
authors : list, str, or unicode
Value or values of 'author' element in DfR XML.
Returns
-------
aulast : list
A list of author surnames (string).
auini... | [
"def",
"_handle_authors",
"(",
"authors",
")",
":",
"aulast",
"=",
"[",
"]",
"auinit",
"=",
"[",
"]",
"if",
"type",
"(",
"authors",
")",
"is",
"list",
":",
"for",
"author",
"in",
"authors",
":",
"if",
"type",
"(",
"author",
")",
"is",
"str",
":",
... | Yields aulast and auinit lists from value of authors node.
Parameters
----------
authors : list, str, or unicode
Value or values of 'author' element in DfR XML.
Returns
-------
aulast : list
A list of author surnames (string).
auinit : list
A list of author first-in... | [
"Yields",
"aulast",
"and",
"auinit",
"lists",
"from",
"value",
"of",
"authors",
"node",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/dfr.py#L462-L505 |
10,066 | diging/tethne | tethne/readers/dfr.py | _handle_author | def _handle_author(author):
"""
Yields aulast and auinit from an author's full name.
Parameters
----------
author : str or unicode
Author fullname, e.g. "Richard L. Nixon".
Returns
-------
aulast : str
Author surname.
auinit : str
Author first-initial.
"... | python | def _handle_author(author):
"""
Yields aulast and auinit from an author's full name.
Parameters
----------
author : str or unicode
Author fullname, e.g. "Richard L. Nixon".
Returns
-------
aulast : str
Author surname.
auinit : str
Author first-initial.
"... | [
"def",
"_handle_author",
"(",
"author",
")",
":",
"lname",
"=",
"author",
".",
"split",
"(",
"' '",
")",
"try",
":",
"auinit",
"=",
"lname",
"[",
"0",
"]",
"[",
"0",
"]",
"final",
"=",
"lname",
"[",
"-",
"1",
"]",
".",
"upper",
"(",
")",
"if",
... | Yields aulast and auinit from an author's full name.
Parameters
----------
author : str or unicode
Author fullname, e.g. "Richard L. Nixon".
Returns
-------
aulast : str
Author surname.
auinit : str
Author first-initial. | [
"Yields",
"aulast",
"and",
"auinit",
"from",
"an",
"author",
"s",
"full",
"name",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/dfr.py#L507-L536 |
10,067 | diging/tethne | tethne/readers/dfr.py | GramGenerator._get | def _get(self, i):
"""
Retrieve data for the ith file in the dataset.
"""
with open(os.path.join(self.path, self.elem, self.files[i]), 'r') as f:
# JSTOR hasn't always produced valid XML.
contents = re.sub('(&)(?!amp;)', lambda match: '&', f.read())
... | python | def _get(self, i):
"""
Retrieve data for the ith file in the dataset.
"""
with open(os.path.join(self.path, self.elem, self.files[i]), 'r') as f:
# JSTOR hasn't always produced valid XML.
contents = re.sub('(&)(?!amp;)', lambda match: '&', f.read())
... | [
"def",
"_get",
"(",
"self",
",",
"i",
")",
":",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"path",
",",
"self",
".",
"elem",
",",
"self",
".",
"files",
"[",
"i",
"]",
")",
",",
"'r'",
")",
"as",
"f",
":",
"# JSTO... | Retrieve data for the ith file in the dataset. | [
"Retrieve",
"data",
"for",
"the",
"ith",
"file",
"in",
"the",
"dataset",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/readers/dfr.py#L175-L198 |
10,068 | diging/tethne | tethne/model/corpus/mallet.py | LDAModel._generate_corpus | def _generate_corpus(self):
"""
Writes a corpus to disk amenable to MALLET topic modeling.
"""
target = self.temp + 'mallet'
paths = write_documents(self.corpus, target, self.featureset_name,
['date', 'title'])
self.corpus_path, self.metap... | python | def _generate_corpus(self):
"""
Writes a corpus to disk amenable to MALLET topic modeling.
"""
target = self.temp + 'mallet'
paths = write_documents(self.corpus, target, self.featureset_name,
['date', 'title'])
self.corpus_path, self.metap... | [
"def",
"_generate_corpus",
"(",
"self",
")",
":",
"target",
"=",
"self",
".",
"temp",
"+",
"'mallet'",
"paths",
"=",
"write_documents",
"(",
"self",
".",
"corpus",
",",
"target",
",",
"self",
".",
"featureset_name",
",",
"[",
"'date'",
",",
"'title'",
"]... | Writes a corpus to disk amenable to MALLET topic modeling. | [
"Writes",
"a",
"corpus",
"to",
"disk",
"amenable",
"to",
"MALLET",
"topic",
"modeling",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/model/corpus/mallet.py#L151-L161 |
10,069 | diging/tethne | tethne/model/corpus/mallet.py | LDAModel._export_corpus | def _export_corpus(self):
"""
Calls MALLET's `import-file` method.
"""
# bin/mallet import-file --input /Users/erickpeirson/mycorpus_docs.txt
# --output mytopic-input.mallet --keep-sequence --remove-stopwords
if not os.path.exists(self.mallet_bin):
raise ... | python | def _export_corpus(self):
"""
Calls MALLET's `import-file` method.
"""
# bin/mallet import-file --input /Users/erickpeirson/mycorpus_docs.txt
# --output mytopic-input.mallet --keep-sequence --remove-stopwords
if not os.path.exists(self.mallet_bin):
raise ... | [
"def",
"_export_corpus",
"(",
"self",
")",
":",
"# bin/mallet import-file --input /Users/erickpeirson/mycorpus_docs.txt",
"# --output mytopic-input.mallet --keep-sequence --remove-stopwords",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"mallet_bin",
")"... | Calls MALLET's `import-file` method. | [
"Calls",
"MALLET",
"s",
"import",
"-",
"file",
"method",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/model/corpus/mallet.py#L163-L184 |
10,070 | diging/tethne | tethne/model/corpus/mallet.py | LDAModel.run | def run(self, **kwargs):
"""
Calls MALLET's `train-topic` method.
"""
#$ bin/mallet train-topics --input mytopic-input.mallet
#> --num-topics 100
#> --output-doc-topics /Users/erickpeirson/doc_top
#> --word-topic-counts-file /Users/erickpeirson/word_top
#>... | python | def run(self, **kwargs):
"""
Calls MALLET's `train-topic` method.
"""
#$ bin/mallet train-topics --input mytopic-input.mallet
#> --num-topics 100
#> --output-doc-topics /Users/erickpeirson/doc_top
#> --word-topic-counts-file /Users/erickpeirson/word_top
#>... | [
"def",
"run",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"#$ bin/mallet train-topics --input mytopic-input.mallet",
"#> --num-topics 100",
"#> --output-doc-topics /Users/erickpeirson/doc_top",
"#> --word-topic-counts-file /Users/erickpeirson/word_top",
"#> --output-topic-keys /Users... | Calls MALLET's `train-topic` method. | [
"Calls",
"MALLET",
"s",
"train",
"-",
"topic",
"method",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/model/corpus/mallet.py#L186-L241 |
10,071 | diging/tethne | tethne/model/corpus/mallet.py | LDAModel.topics_in | def topics_in(self, d, topn=5):
"""
List the top ``topn`` topics in document ``d``.
"""
return self.theta.features[d].top(topn) | python | def topics_in(self, d, topn=5):
"""
List the top ``topn`` topics in document ``d``.
"""
return self.theta.features[d].top(topn) | [
"def",
"topics_in",
"(",
"self",
",",
"d",
",",
"topn",
"=",
"5",
")",
":",
"return",
"self",
".",
"theta",
".",
"features",
"[",
"d",
"]",
".",
"top",
"(",
"topn",
")"
] | List the top ``topn`` topics in document ``d``. | [
"List",
"the",
"top",
"topn",
"topics",
"in",
"document",
"d",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/model/corpus/mallet.py#L307-L311 |
10,072 | diging/tethne | tethne/model/corpus/mallet.py | LDAModel.list_topic | def list_topic(self, k, Nwords=10):
"""
List the top ``topn`` words for topic ``k``.
Examples
--------
.. code-block:: python
>>> model.list_topic(1, Nwords=5)
[ 'opposed', 'terminates', 'trichinosis', 'cistus', 'acaule' ]
"""
return [(... | python | def list_topic(self, k, Nwords=10):
"""
List the top ``topn`` words for topic ``k``.
Examples
--------
.. code-block:: python
>>> model.list_topic(1, Nwords=5)
[ 'opposed', 'terminates', 'trichinosis', 'cistus', 'acaule' ]
"""
return [(... | [
"def",
"list_topic",
"(",
"self",
",",
"k",
",",
"Nwords",
"=",
"10",
")",
":",
"return",
"[",
"(",
"self",
".",
"vocabulary",
"[",
"w",
"]",
",",
"p",
")",
"for",
"w",
",",
"p",
"in",
"self",
".",
"phi",
".",
"features",
"[",
"k",
"]",
".",
... | List the top ``topn`` words for topic ``k``.
Examples
--------
.. code-block:: python
>>> model.list_topic(1, Nwords=5)
[ 'opposed', 'terminates', 'trichinosis', 'cistus', 'acaule' ] | [
"List",
"the",
"top",
"topn",
"words",
"for",
"topic",
"k",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/model/corpus/mallet.py#L313-L329 |
10,073 | diging/tethne | tethne/model/corpus/mallet.py | LDAModel.list_topics | def list_topics(self, Nwords=10):
"""
List the top ``Nwords`` words for each topic.
"""
return [(k, self.list_topic(k, Nwords)) for k in xrange(len(self.phi))] | python | def list_topics(self, Nwords=10):
"""
List the top ``Nwords`` words for each topic.
"""
return [(k, self.list_topic(k, Nwords)) for k in xrange(len(self.phi))] | [
"def",
"list_topics",
"(",
"self",
",",
"Nwords",
"=",
"10",
")",
":",
"return",
"[",
"(",
"k",
",",
"self",
".",
"list_topic",
"(",
"k",
",",
"Nwords",
")",
")",
"for",
"k",
"in",
"xrange",
"(",
"len",
"(",
"self",
".",
"phi",
")",
")",
"]"
] | List the top ``Nwords`` words for each topic. | [
"List",
"the",
"top",
"Nwords",
"words",
"for",
"each",
"topic",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/model/corpus/mallet.py#L331-L335 |
10,074 | diging/tethne | tethne/model/corpus/mallet.py | LDAModel.print_topics | def print_topics(self, Nwords=10):
"""
Print the top ``Nwords`` words for each topic.
"""
print('Topic\tTop %i words' % Nwords)
for k, words in self.list_topics(Nwords):
print(unicode(k).ljust(3) + '\t' + ' '.join(list(zip(*words))[0])) | python | def print_topics(self, Nwords=10):
"""
Print the top ``Nwords`` words for each topic.
"""
print('Topic\tTop %i words' % Nwords)
for k, words in self.list_topics(Nwords):
print(unicode(k).ljust(3) + '\t' + ' '.join(list(zip(*words))[0])) | [
"def",
"print_topics",
"(",
"self",
",",
"Nwords",
"=",
"10",
")",
":",
"print",
"(",
"'Topic\\tTop %i words'",
"%",
"Nwords",
")",
"for",
"k",
",",
"words",
"in",
"self",
".",
"list_topics",
"(",
"Nwords",
")",
":",
"print",
"(",
"unicode",
"(",
"k",
... | Print the top ``Nwords`` words for each topic. | [
"Print",
"the",
"top",
"Nwords",
"words",
"for",
"each",
"topic",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/model/corpus/mallet.py#L338-L344 |
10,075 | diging/tethne | tethne/model/corpus/mallet.py | LDAModel.topic_over_time | def topic_over_time(self, k, mode='counts', slice_kwargs={}):
"""
Calculate the representation of topic ``k`` in the corpus over time.
"""
return self.corpus.feature_distribution('topics', k, mode=mode,
**slice_kwargs) | python | def topic_over_time(self, k, mode='counts', slice_kwargs={}):
"""
Calculate the representation of topic ``k`` in the corpus over time.
"""
return self.corpus.feature_distribution('topics', k, mode=mode,
**slice_kwargs) | [
"def",
"topic_over_time",
"(",
"self",
",",
"k",
",",
"mode",
"=",
"'counts'",
",",
"slice_kwargs",
"=",
"{",
"}",
")",
":",
"return",
"self",
".",
"corpus",
".",
"feature_distribution",
"(",
"'topics'",
",",
"k",
",",
"mode",
"=",
"mode",
",",
"*",
... | Calculate the representation of topic ``k`` in the corpus over time. | [
"Calculate",
"the",
"representation",
"of",
"topic",
"k",
"in",
"the",
"corpus",
"over",
"time",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/model/corpus/mallet.py#L347-L353 |
10,076 | diging/tethne | tethne/classes/corpus.py | Corpus.distribution | def distribution(self, **slice_kwargs):
"""
Calculates the number of papers in each slice, as defined by
``slice_kwargs``.
Examples
--------
.. code-block:: python
>>> corpus.distribution(step_size=1, window_size=1)
[5, 5]
Parameters
... | python | def distribution(self, **slice_kwargs):
"""
Calculates the number of papers in each slice, as defined by
``slice_kwargs``.
Examples
--------
.. code-block:: python
>>> corpus.distribution(step_size=1, window_size=1)
[5, 5]
Parameters
... | [
"def",
"distribution",
"(",
"self",
",",
"*",
"*",
"slice_kwargs",
")",
":",
"values",
"=",
"[",
"]",
"keys",
"=",
"[",
"]",
"for",
"key",
",",
"size",
"in",
"self",
".",
"slice",
"(",
"count_only",
"=",
"True",
",",
"*",
"*",
"slice_kwargs",
")",
... | Calculates the number of papers in each slice, as defined by
``slice_kwargs``.
Examples
--------
.. code-block:: python
>>> corpus.distribution(step_size=1, window_size=1)
[5, 5]
Parameters
----------
slice_kwargs : kwargs
Keyw... | [
"Calculates",
"the",
"number",
"of",
"papers",
"in",
"each",
"slice",
"as",
"defined",
"by",
"slice_kwargs",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/classes/corpus.py#L595-L622 |
10,077 | diging/tethne | tethne/classes/corpus.py | Corpus.feature_distribution | def feature_distribution(self, featureset_name, feature, mode='counts',
**slice_kwargs):
"""
Calculates the distribution of a feature across slices of the corpus.
Examples
--------
.. code-block:: python
>>> corpus.feature_distribution(fe... | python | def feature_distribution(self, featureset_name, feature, mode='counts',
**slice_kwargs):
"""
Calculates the distribution of a feature across slices of the corpus.
Examples
--------
.. code-block:: python
>>> corpus.feature_distribution(fe... | [
"def",
"feature_distribution",
"(",
"self",
",",
"featureset_name",
",",
"feature",
",",
"mode",
"=",
"'counts'",
",",
"*",
"*",
"slice_kwargs",
")",
":",
"values",
"=",
"[",
"]",
"keys",
"=",
"[",
"]",
"fset",
"=",
"self",
".",
"features",
"[",
"featu... | Calculates the distribution of a feature across slices of the corpus.
Examples
--------
.. code-block:: python
>>> corpus.feature_distribution(featureset_name='citations', \
... feature='DOLE RJ 1965 CELL', \
... ... | [
"Calculates",
"the",
"distribution",
"of",
"a",
"feature",
"across",
"slices",
"of",
"the",
"corpus",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/classes/corpus.py#L624-L685 |
10,078 | diging/tethne | tethne/classes/corpus.py | Corpus.top_features | def top_features(self, featureset_name, topn=20, by='counts',
perslice=False, slice_kwargs={}):
"""
Retrieves the top ``topn`` most numerous features in the corpus.
Parameters
----------
featureset_name : str
Name of a :class:`.FeatureSet` in the... | python | def top_features(self, featureset_name, topn=20, by='counts',
perslice=False, slice_kwargs={}):
"""
Retrieves the top ``topn`` most numerous features in the corpus.
Parameters
----------
featureset_name : str
Name of a :class:`.FeatureSet` in the... | [
"def",
"top_features",
"(",
"self",
",",
"featureset_name",
",",
"topn",
"=",
"20",
",",
"by",
"=",
"'counts'",
",",
"perslice",
"=",
"False",
",",
"slice_kwargs",
"=",
"{",
"}",
")",
":",
"if",
"perslice",
":",
"return",
"[",
"(",
"k",
",",
"subcorp... | Retrieves the top ``topn`` most numerous features in the corpus.
Parameters
----------
featureset_name : str
Name of a :class:`.FeatureSet` in the :class:`.Corpus`\.
topn : int
(default: ``20``) Number of features to return.
by : str
(default:... | [
"Retrieves",
"the",
"top",
"topn",
"most",
"numerous",
"features",
"in",
"the",
"corpus",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/classes/corpus.py#L687-L713 |
10,079 | diging/tethne | tethne/analyze/corpus.py | feature_burstness | def feature_burstness(corpus, featureset_name, feature, k=5, normalize=True,
s=1.1, gamma=1., **slice_kwargs):
"""
Estimate burstness profile for a feature over the ``'date'`` axis.
Parameters
----------
corpus : :class:`.Corpus`
feature : str
Name of featureset in... | python | def feature_burstness(corpus, featureset_name, feature, k=5, normalize=True,
s=1.1, gamma=1., **slice_kwargs):
"""
Estimate burstness profile for a feature over the ``'date'`` axis.
Parameters
----------
corpus : :class:`.Corpus`
feature : str
Name of featureset in... | [
"def",
"feature_burstness",
"(",
"corpus",
",",
"featureset_name",
",",
"feature",
",",
"k",
"=",
"5",
",",
"normalize",
"=",
"True",
",",
"s",
"=",
"1.1",
",",
"gamma",
"=",
"1.",
",",
"*",
"*",
"slice_kwargs",
")",
":",
"if",
"featureset_name",
"not"... | Estimate burstness profile for a feature over the ``'date'`` axis.
Parameters
----------
corpus : :class:`.Corpus`
feature : str
Name of featureset in ``corpus``. E.g. ``'citations'``.
findex : int
Index of ``feature`` in ``corpus``.
k : int
(default: 5) Number of burst ... | [
"Estimate",
"burstness",
"profile",
"for",
"a",
"feature",
"over",
"the",
"date",
"axis",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/analyze/corpus.py#L157-L224 |
10,080 | diging/tethne | tethne/networks/papers.py | cocitation | def cocitation(corpus, min_weight=1, edge_attrs=['ayjid', 'date'], **kwargs):
"""
Generate a cocitation network.
A **cocitation network** is a network in which vertices are papers, and
edges indicate that two papers were cited by the same third paper.
`CiteSpace
<http://cluster.cis.drexel.edu/~... | python | def cocitation(corpus, min_weight=1, edge_attrs=['ayjid', 'date'], **kwargs):
"""
Generate a cocitation network.
A **cocitation network** is a network in which vertices are papers, and
edges indicate that two papers were cited by the same third paper.
`CiteSpace
<http://cluster.cis.drexel.edu/~... | [
"def",
"cocitation",
"(",
"corpus",
",",
"min_weight",
"=",
"1",
",",
"edge_attrs",
"=",
"[",
"'ayjid'",
",",
"'date'",
"]",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"cooccurrence",
"(",
"corpus",
",",
"'citations'",
",",
"min_weight",
"=",
"min_weig... | Generate a cocitation network.
A **cocitation network** is a network in which vertices are papers, and
edges indicate that two papers were cited by the same third paper.
`CiteSpace
<http://cluster.cis.drexel.edu/~cchen/citespace/doc/jasist2006.pdf>`_
is a popular desktop application for co-citation... | [
"Generate",
"a",
"cocitation",
"network",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/networks/papers.py#L43-L56 |
10,081 | diging/tethne | tethne/classes/feature.py | StructuredFeature.context_chunk | def context_chunk(self, context, j):
"""
Retrieve the tokens in the ``j``th chunk of context ``context``.
Parameters
----------
context : str
Context name.
j : int
Index of a context chunk.
Returns
-------
chunk : list
... | python | def context_chunk(self, context, j):
"""
Retrieve the tokens in the ``j``th chunk of context ``context``.
Parameters
----------
context : str
Context name.
j : int
Index of a context chunk.
Returns
-------
chunk : list
... | [
"def",
"context_chunk",
"(",
"self",
",",
"context",
",",
"j",
")",
":",
"N_chunks",
"=",
"len",
"(",
"self",
".",
"contexts",
"[",
"context",
"]",
")",
"start",
"=",
"self",
".",
"contexts",
"[",
"context",
"]",
"[",
"j",
"]",
"if",
"j",
"==",
"... | Retrieve the tokens in the ``j``th chunk of context ``context``.
Parameters
----------
context : str
Context name.
j : int
Index of a context chunk.
Returns
-------
chunk : list
List of tokens in the selected chunk. | [
"Retrieve",
"the",
"tokens",
"in",
"the",
"j",
"th",
"chunk",
"of",
"context",
"context",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/classes/feature.py#L108-L131 |
10,082 | diging/tethne | tethne/classes/feature.py | StructuredFeature.add_context | def add_context(self, name, indices, level=None):
"""
Add a new context level to the hierarchy.
By default, new contexts are added to the lowest level of the hierarchy.
To insert the context elsewhere in the hierarchy, use the ``level``
argument. For example, ``level=0`` would i... | python | def add_context(self, name, indices, level=None):
"""
Add a new context level to the hierarchy.
By default, new contexts are added to the lowest level of the hierarchy.
To insert the context elsewhere in the hierarchy, use the ``level``
argument. For example, ``level=0`` would i... | [
"def",
"add_context",
"(",
"self",
",",
"name",
",",
"indices",
",",
"level",
"=",
"None",
")",
":",
"self",
".",
"_validate_context",
"(",
"(",
"name",
",",
"indices",
")",
")",
"if",
"level",
"is",
"None",
":",
"level",
"=",
"len",
"(",
"self",
"... | Add a new context level to the hierarchy.
By default, new contexts are added to the lowest level of the hierarchy.
To insert the context elsewhere in the hierarchy, use the ``level``
argument. For example, ``level=0`` would insert the context at the
highest level of the hierarchy.
... | [
"Add",
"a",
"new",
"context",
"level",
"to",
"the",
"hierarchy",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/classes/feature.py#L170-L195 |
10,083 | diging/tethne | tethne/classes/graphcollection.py | GraphCollection.index | def index(self, name, graph):
"""
Index any new nodes in `graph`, and relabel the nodes in `graph` using
the index.
Parameters
----------
name : hashable
Unique name used to identify the `graph`.
graph : networkx.Graph
Returns
-------... | python | def index(self, name, graph):
"""
Index any new nodes in `graph`, and relabel the nodes in `graph` using
the index.
Parameters
----------
name : hashable
Unique name used to identify the `graph`.
graph : networkx.Graph
Returns
-------... | [
"def",
"index",
"(",
"self",
",",
"name",
",",
"graph",
")",
":",
"nodes",
"=",
"graph",
".",
"nodes",
"(",
")",
"# Index new nodes.",
"new_nodes",
"=",
"list",
"(",
"set",
"(",
"nodes",
")",
"-",
"set",
"(",
"self",
".",
"node_index",
".",
"values",... | Index any new nodes in `graph`, and relabel the nodes in `graph` using
the index.
Parameters
----------
name : hashable
Unique name used to identify the `graph`.
graph : networkx.Graph
Returns
-------
indexed_graph : networkx.Graph | [
"Index",
"any",
"new",
"nodes",
"in",
"graph",
"and",
"relabel",
"the",
"nodes",
"in",
"graph",
"using",
"the",
"index",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/classes/graphcollection.py#L159-L188 |
10,084 | diging/tethne | tethne/networks/topics.py | terms | def terms(model, threshold=0.01, **kwargs):
"""
Two terms are coupled if the posterior probability for both terms is
greather than ``threshold`` for the same topic.
Parameters
----------
model : :class:`.LDAModel`
threshold : float
Default: 0.01
kwargs : kwargs
Passed on... | python | def terms(model, threshold=0.01, **kwargs):
"""
Two terms are coupled if the posterior probability for both terms is
greather than ``threshold`` for the same topic.
Parameters
----------
model : :class:`.LDAModel`
threshold : float
Default: 0.01
kwargs : kwargs
Passed on... | [
"def",
"terms",
"(",
"model",
",",
"threshold",
"=",
"0.01",
",",
"*",
"*",
"kwargs",
")",
":",
"select",
"=",
"lambda",
"f",
",",
"v",
",",
"c",
",",
"dc",
":",
"v",
">",
"threshold",
"graph",
"=",
"cooccurrence",
"(",
"model",
".",
"phi",
",",
... | Two terms are coupled if the posterior probability for both terms is
greather than ``threshold`` for the same topic.
Parameters
----------
model : :class:`.LDAModel`
threshold : float
Default: 0.01
kwargs : kwargs
Passed on to :func:`.cooccurrence`\.
Returns
-------
... | [
"Two",
"terms",
"are",
"coupled",
"if",
"the",
"posterior",
"probability",
"for",
"both",
"terms",
"is",
"greather",
"than",
"threshold",
"for",
"the",
"same",
"topic",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/networks/topics.py#L24-L50 |
10,085 | diging/tethne | tethne/networks/topics.py | topic_coupling | def topic_coupling(model, threshold=None, **kwargs):
"""
Two papers are coupled if they both contain a shared topic above a
``threshold``.
Parameters
----------
model : :class:`.LDAModel`
threshold : float
Default: ``3./model.Z``
kwargs : kwargs
Passed on to :func:`.coup... | python | def topic_coupling(model, threshold=None, **kwargs):
"""
Two papers are coupled if they both contain a shared topic above a
``threshold``.
Parameters
----------
model : :class:`.LDAModel`
threshold : float
Default: ``3./model.Z``
kwargs : kwargs
Passed on to :func:`.coup... | [
"def",
"topic_coupling",
"(",
"model",
",",
"threshold",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"threshold",
":",
"threshold",
"=",
"3.",
"/",
"model",
".",
"Z",
"select",
"=",
"lambda",
"f",
",",
"v",
",",
"c",
",",
"dc",
"... | Two papers are coupled if they both contain a shared topic above a
``threshold``.
Parameters
----------
model : :class:`.LDAModel`
threshold : float
Default: ``3./model.Z``
kwargs : kwargs
Passed on to :func:`.coupling`\.
Returns
-------
:ref:`networkx.Graph <networ... | [
"Two",
"papers",
"are",
"coupled",
"if",
"they",
"both",
"contain",
"a",
"shared",
"topic",
"above",
"a",
"threshold",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/networks/topics.py#L53-L77 |
10,086 | diging/tethne | tethne/analyze/features.py | kl_divergence | def kl_divergence(V_a, V_b):
"""
Calculate Kullback-Leibler distance.
Uses the smoothing method described in `Bigi 2003
<http://lvk.cs.msu.su/~bruzz/articles/classification/Using%20Kullback-Leibler%20Distance%20for%20Text%20Categorization.pdf>`_
to facilitate better comparisons between vectors desc... | python | def kl_divergence(V_a, V_b):
"""
Calculate Kullback-Leibler distance.
Uses the smoothing method described in `Bigi 2003
<http://lvk.cs.msu.su/~bruzz/articles/classification/Using%20Kullback-Leibler%20Distance%20for%20Text%20Categorization.pdf>`_
to facilitate better comparisons between vectors desc... | [
"def",
"kl_divergence",
"(",
"V_a",
",",
"V_b",
")",
":",
"# Find shared features.",
"Ndiff",
"=",
"_shared_features",
"(",
"V_a",
",",
"V_b",
")",
"# aprob and bprob should each sum to 1.0",
"aprob",
"=",
"map",
"(",
"lambda",
"v",
":",
"float",
"(",
"v",
")"... | Calculate Kullback-Leibler distance.
Uses the smoothing method described in `Bigi 2003
<http://lvk.cs.msu.su/~bruzz/articles/classification/Using%20Kullback-Leibler%20Distance%20for%20Text%20Categorization.pdf>`_
to facilitate better comparisons between vectors describing wordcounts.
Parameters
--... | [
"Calculate",
"Kullback",
"-",
"Leibler",
"distance",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/analyze/features.py#L18-L47 |
10,087 | diging/tethne | tethne/analyze/features.py | _shared_features | def _shared_features(adense, bdense):
"""
Number of features in ``adense`` that are also in ``bdense``.
"""
a_indices = set(nonzero(adense))
b_indices = set(nonzero(bdense))
shared = list(a_indices & b_indices)
diff = list(a_indices - b_indices)
Ndiff = len(diff)
return Ndiff | python | def _shared_features(adense, bdense):
"""
Number of features in ``adense`` that are also in ``bdense``.
"""
a_indices = set(nonzero(adense))
b_indices = set(nonzero(bdense))
shared = list(a_indices & b_indices)
diff = list(a_indices - b_indices)
Ndiff = len(diff)
return Ndiff | [
"def",
"_shared_features",
"(",
"adense",
",",
"bdense",
")",
":",
"a_indices",
"=",
"set",
"(",
"nonzero",
"(",
"adense",
")",
")",
"b_indices",
"=",
"set",
"(",
"nonzero",
"(",
"bdense",
")",
")",
"shared",
"=",
"list",
"(",
"a_indices",
"&",
"b_indi... | Number of features in ``adense`` that are also in ``bdense``. | [
"Number",
"of",
"features",
"in",
"adense",
"that",
"are",
"also",
"in",
"bdense",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/analyze/features.py#L100-L111 |
10,088 | diging/tethne | tethne/networks/base.py | cooccurrence | def cooccurrence(corpus_or_featureset, featureset_name=None, min_weight=1,
edge_attrs=['ayjid', 'date'],
filter=None):
"""
A network of feature elements linked by their joint occurrence in papers.
"""
if not filter:
filter = lambda f, v, c, dc: dc >= min_weight... | python | def cooccurrence(corpus_or_featureset, featureset_name=None, min_weight=1,
edge_attrs=['ayjid', 'date'],
filter=None):
"""
A network of feature elements linked by their joint occurrence in papers.
"""
if not filter:
filter = lambda f, v, c, dc: dc >= min_weight... | [
"def",
"cooccurrence",
"(",
"corpus_or_featureset",
",",
"featureset_name",
"=",
"None",
",",
"min_weight",
"=",
"1",
",",
"edge_attrs",
"=",
"[",
"'ayjid'",
",",
"'date'",
"]",
",",
"filter",
"=",
"None",
")",
":",
"if",
"not",
"filter",
":",
"filter",
... | A network of feature elements linked by their joint occurrence in papers. | [
"A",
"network",
"of",
"feature",
"elements",
"linked",
"by",
"their",
"joint",
"occurrence",
"in",
"papers",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/networks/base.py#L39-L93 |
10,089 | diging/tethne | tethne/networks/base.py | coupling | def coupling(corpus_or_featureset, featureset_name=None,
min_weight=1, filter=lambda f, v, c, dc: True,
node_attrs=[]):
"""
A network of papers linked by their joint posession of features.
"""
featureset = _get_featureset(corpus_or_featureset, featureset_name)
c = lambda ... | python | def coupling(corpus_or_featureset, featureset_name=None,
min_weight=1, filter=lambda f, v, c, dc: True,
node_attrs=[]):
"""
A network of papers linked by their joint posession of features.
"""
featureset = _get_featureset(corpus_or_featureset, featureset_name)
c = lambda ... | [
"def",
"coupling",
"(",
"corpus_or_featureset",
",",
"featureset_name",
"=",
"None",
",",
"min_weight",
"=",
"1",
",",
"filter",
"=",
"lambda",
"f",
",",
"v",
",",
"c",
",",
"dc",
":",
"True",
",",
"node_attrs",
"=",
"[",
"]",
")",
":",
"featureset",
... | A network of papers linked by their joint posession of features. | [
"A",
"network",
"of",
"papers",
"linked",
"by",
"their",
"joint",
"posession",
"of",
"features",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/networks/base.py#L97-L140 |
10,090 | diging/tethne | tethne/networks/base.py | multipartite | def multipartite(corpus, featureset_names, min_weight=1, filters={}):
"""
A network of papers and one or more featuresets.
"""
pairs = Counter()
node_type = {corpus._generate_index(p): {'type': 'paper'}
for p in corpus.papers}
for featureset_name in featureset_names:
ft... | python | def multipartite(corpus, featureset_names, min_weight=1, filters={}):
"""
A network of papers and one or more featuresets.
"""
pairs = Counter()
node_type = {corpus._generate_index(p): {'type': 'paper'}
for p in corpus.papers}
for featureset_name in featureset_names:
ft... | [
"def",
"multipartite",
"(",
"corpus",
",",
"featureset_names",
",",
"min_weight",
"=",
"1",
",",
"filters",
"=",
"{",
"}",
")",
":",
"pairs",
"=",
"Counter",
"(",
")",
"node_type",
"=",
"{",
"corpus",
".",
"_generate_index",
"(",
"p",
")",
":",
"{",
... | A network of papers and one or more featuresets. | [
"A",
"network",
"of",
"papers",
"and",
"one",
"or",
"more",
"featuresets",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/networks/base.py#L143-L167 |
10,091 | diging/tethne | tethne/utilities.py | _strip_punctuation | def _strip_punctuation(s):
"""
Removes all punctuation characters from a string.
"""
if type(s) is str and not PYTHON_3: # Bytestring (default in Python 2.x).
return s.translate(string.maketrans("",""), string.punctuation)
else: # Unicode string (default in Python 3.x).
... | python | def _strip_punctuation(s):
"""
Removes all punctuation characters from a string.
"""
if type(s) is str and not PYTHON_3: # Bytestring (default in Python 2.x).
return s.translate(string.maketrans("",""), string.punctuation)
else: # Unicode string (default in Python 3.x).
... | [
"def",
"_strip_punctuation",
"(",
"s",
")",
":",
"if",
"type",
"(",
"s",
")",
"is",
"str",
"and",
"not",
"PYTHON_3",
":",
"# Bytestring (default in Python 2.x).",
"return",
"s",
".",
"translate",
"(",
"string",
".",
"maketrans",
"(",
"\"\"",
",",
"\"\"",
"... | Removes all punctuation characters from a string. | [
"Removes",
"all",
"punctuation",
"characters",
"from",
"a",
"string",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/utilities.py#L115-L123 |
10,092 | diging/tethne | tethne/utilities.py | overlap | def overlap(listA, listB):
"""
Return list of objects shared by listA, listB.
"""
if (listA is None) or (listB is None):
return []
else:
return list(set(listA) & set(listB)) | python | def overlap(listA, listB):
"""
Return list of objects shared by listA, listB.
"""
if (listA is None) or (listB is None):
return []
else:
return list(set(listA) & set(listB)) | [
"def",
"overlap",
"(",
"listA",
",",
"listB",
")",
":",
"if",
"(",
"listA",
"is",
"None",
")",
"or",
"(",
"listB",
"is",
"None",
")",
":",
"return",
"[",
"]",
"else",
":",
"return",
"list",
"(",
"set",
"(",
"listA",
")",
"&",
"set",
"(",
"listB... | Return list of objects shared by listA, listB. | [
"Return",
"list",
"of",
"objects",
"shared",
"by",
"listA",
"listB",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/utilities.py#L174-L181 |
10,093 | diging/tethne | tethne/utilities.py | subdict | def subdict(super_dict, keys):
"""
Returns a subset of the super_dict with the specified keys.
"""
sub_dict = {}
valid_keys = super_dict.keys()
for key in keys:
if key in valid_keys:
sub_dict[key] = super_dict[key]
return sub_dict | python | def subdict(super_dict, keys):
"""
Returns a subset of the super_dict with the specified keys.
"""
sub_dict = {}
valid_keys = super_dict.keys()
for key in keys:
if key in valid_keys:
sub_dict[key] = super_dict[key]
return sub_dict | [
"def",
"subdict",
"(",
"super_dict",
",",
"keys",
")",
":",
"sub_dict",
"=",
"{",
"}",
"valid_keys",
"=",
"super_dict",
".",
"keys",
"(",
")",
"for",
"key",
"in",
"keys",
":",
"if",
"key",
"in",
"valid_keys",
":",
"sub_dict",
"[",
"key",
"]",
"=",
... | Returns a subset of the super_dict with the specified keys. | [
"Returns",
"a",
"subset",
"of",
"the",
"super_dict",
"with",
"the",
"specified",
"keys",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/utilities.py#L184-L194 |
10,094 | diging/tethne | tethne/utilities.py | concat_list | def concat_list(listA, listB, delim=' '):
"""
Concatenate list elements pair-wise with the delim character
Returns the concatenated list
Raises index error if lists are not parallel
"""
# Lists must be of equal length.
if len(listA) != len(listB):
raise IndexError('Input lists are n... | python | def concat_list(listA, listB, delim=' '):
"""
Concatenate list elements pair-wise with the delim character
Returns the concatenated list
Raises index error if lists are not parallel
"""
# Lists must be of equal length.
if len(listA) != len(listB):
raise IndexError('Input lists are n... | [
"def",
"concat_list",
"(",
"listA",
",",
"listB",
",",
"delim",
"=",
"' '",
")",
":",
"# Lists must be of equal length.",
"if",
"len",
"(",
"listA",
")",
"!=",
"len",
"(",
"listB",
")",
":",
"raise",
"IndexError",
"(",
"'Input lists are not parallel.'",
")",
... | Concatenate list elements pair-wise with the delim character
Returns the concatenated list
Raises index error if lists are not parallel | [
"Concatenate",
"list",
"elements",
"pair",
"-",
"wise",
"with",
"the",
"delim",
"character",
"Returns",
"the",
"concatenated",
"list",
"Raises",
"index",
"error",
"if",
"lists",
"are",
"not",
"parallel"
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/utilities.py#L212-L229 |
10,095 | diging/tethne | tethne/utilities.py | strip_non_ascii | def strip_non_ascii(s):
"""
Returns the string without non-ASCII characters.
Parameters
----------
string : string
A string that may contain non-ASCII characters.
Returns
-------
clean_string : string
A string that does not contain non-ASCII characters.
"""
str... | python | def strip_non_ascii(s):
"""
Returns the string without non-ASCII characters.
Parameters
----------
string : string
A string that may contain non-ASCII characters.
Returns
-------
clean_string : string
A string that does not contain non-ASCII characters.
"""
str... | [
"def",
"strip_non_ascii",
"(",
"s",
")",
":",
"stripped",
"=",
"(",
"c",
"for",
"c",
"in",
"s",
"if",
"0",
"<",
"ord",
"(",
"c",
")",
"<",
"127",
")",
"clean_string",
"=",
"u''",
".",
"join",
"(",
"stripped",
")",
"return",
"clean_string"
] | Returns the string without non-ASCII characters.
Parameters
----------
string : string
A string that may contain non-ASCII characters.
Returns
-------
clean_string : string
A string that does not contain non-ASCII characters. | [
"Returns",
"the",
"string",
"without",
"non",
"-",
"ASCII",
"characters",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/utilities.py#L231-L248 |
10,096 | diging/tethne | tethne/utilities.py | dict_from_node | def dict_from_node(node, recursive=False):
"""
Converts ElementTree node to a dictionary.
Parameters
----------
node : ElementTree node
recursive : boolean
If recursive=False, the value of any field with children will be the
number of children.
Returns
-------
dict ... | python | def dict_from_node(node, recursive=False):
"""
Converts ElementTree node to a dictionary.
Parameters
----------
node : ElementTree node
recursive : boolean
If recursive=False, the value of any field with children will be the
number of children.
Returns
-------
dict ... | [
"def",
"dict_from_node",
"(",
"node",
",",
"recursive",
"=",
"False",
")",
":",
"dict",
"=",
"{",
"}",
"for",
"snode",
"in",
"node",
":",
"if",
"len",
"(",
"snode",
")",
">",
"0",
":",
"if",
"recursive",
":",
"# Will drill down until len(snode) <= 0.",
"... | Converts ElementTree node to a dictionary.
Parameters
----------
node : ElementTree node
recursive : boolean
If recursive=False, the value of any field with children will be the
number of children.
Returns
-------
dict : nested dictionary.
Tags as keys and values as... | [
"Converts",
"ElementTree",
"node",
"to",
"a",
"dictionary",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/utilities.py#L255-L298 |
10,097 | diging/tethne | tethne/utilities.py | MLStripper.feed | def feed(self, data):
"""
added this check as sometimes we are getting the data in integer format instead of string
"""
try:
self.rawdata = self.rawdata + data
except TypeError:
data = unicode(data)
self.rawdata = self.rawdata + data
s... | python | def feed(self, data):
"""
added this check as sometimes we are getting the data in integer format instead of string
"""
try:
self.rawdata = self.rawdata + data
except TypeError:
data = unicode(data)
self.rawdata = self.rawdata + data
s... | [
"def",
"feed",
"(",
"self",
",",
"data",
")",
":",
"try",
":",
"self",
".",
"rawdata",
"=",
"self",
".",
"rawdata",
"+",
"data",
"except",
"TypeError",
":",
"data",
"=",
"unicode",
"(",
"data",
")",
"self",
".",
"rawdata",
"=",
"self",
".",
"rawdat... | added this check as sometimes we are getting the data in integer format instead of string | [
"added",
"this",
"check",
"as",
"sometimes",
"we",
"are",
"getting",
"the",
"data",
"in",
"integer",
"format",
"instead",
"of",
"string"
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/utilities.py#L50-L60 |
10,098 | diging/tethne | tethne/serialize/paper.py | Serialize.serializePaper | def serializePaper(self):
"""
This method creates a fixture for the "django-tethne_paper" model.
Returns
-------
paper_details in JSON format, which can written to a file.
"""
pid = tethnedao.getMaxPaperID();
papers_details = []
for paper in sel... | python | def serializePaper(self):
"""
This method creates a fixture for the "django-tethne_paper" model.
Returns
-------
paper_details in JSON format, which can written to a file.
"""
pid = tethnedao.getMaxPaperID();
papers_details = []
for paper in sel... | [
"def",
"serializePaper",
"(",
"self",
")",
":",
"pid",
"=",
"tethnedao",
".",
"getMaxPaperID",
"(",
")",
"papers_details",
"=",
"[",
"]",
"for",
"paper",
"in",
"self",
".",
"corpus",
":",
"pid",
"=",
"pid",
"+",
"1",
"paper_key",
"=",
"getattr",
"(",
... | This method creates a fixture for the "django-tethne_paper" model.
Returns
-------
paper_details in JSON format, which can written to a file. | [
"This",
"method",
"creates",
"a",
"fixture",
"for",
"the",
"django",
"-",
"tethne_paper",
"model",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/serialize/paper.py#L108-L137 |
10,099 | diging/tethne | tethne/serialize/paper.py | Serialize.serializeCitation | def serializeCitation(self):
"""
This method creates a fixture for the "django-tethne_citation" model.
Returns
-------
citation details which can be written to a file
"""
citation_details = []
citation_id = tethnedao.getMaxCitationID()
for citati... | python | def serializeCitation(self):
"""
This method creates a fixture for the "django-tethne_citation" model.
Returns
-------
citation details which can be written to a file
"""
citation_details = []
citation_id = tethnedao.getMaxCitationID()
for citati... | [
"def",
"serializeCitation",
"(",
"self",
")",
":",
"citation_details",
"=",
"[",
"]",
"citation_id",
"=",
"tethnedao",
".",
"getMaxCitationID",
"(",
")",
"for",
"citation",
"in",
"self",
".",
"corpus",
".",
"features",
"[",
"'citations'",
"]",
".",
"index",
... | This method creates a fixture for the "django-tethne_citation" model.
Returns
-------
citation details which can be written to a file | [
"This",
"method",
"creates",
"a",
"fixture",
"for",
"the",
"django",
"-",
"tethne_citation",
"model",
"."
] | ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/serialize/paper.py#L210-L246 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.