Gismo#

Tools to make gismos. WIP

class gismap.gismo.GismoLab(lab, ngram_range=(1, 3), stop_words=None)[source]#

Cross-embedding of a lab’s authors and the words of their publications.

Built on Gismo’s XGismo, it relates authors to the vocabulary of their work, so a single object answers keyword queries by topic, by author, by group, or for the whole lab. Building it embeds every publication twice (words and authors), so reuse one instance across queries rather than rebuilding per call (e.g. LabMap.wordcloud rebuilds each time).

Parameters:
  • lab (LabMap) – A populated lab (update_publis / build must have run).

  • ngram_range (tuple, default=(1, 3)) – N-gram range for the keyword vectorizer.

  • stop_words (list, optional) – Stop words for the keyword vectorizer. Defaults to the package list (English + French + academic noise).

keywords(query=None, group=None, y=True, k=50, threshold=50, length_impact=0.1)[source]#

Return ranked (word, weight) pairs, with near-duplicate n-grams merged.

Parameters:
  • query (str or list, optional) – A text query (y=True), or a list of author keys (y=False). Defaults to the whole lab (empty query).

  • group (str, optional) – Restrict to the authors of this group (overrides query).

  • y – Ranking and de-duplication tuning (see Gismo / similarity_matrix).

  • k – Ranking and de-duplication tuning (see Gismo / similarity_matrix).

  • threshold – Ranking and de-duplication tuning (see Gismo / similarity_matrix).

  • length_impact – Ranking and de-duplication tuning (see Gismo / similarity_matrix).

wordcloud(query=None, group=None, **kwargs)[source]#

Like keywords(), but wrapped in a renderable WordCloud.

class gismap.gismo.WordCloud(words, title=None)[source]#

A set of (word, weight) pairs with a self-contained HTML rendering.

Displays natively in notebooks via _repr_html_ (font size and colour follow the weight); to_html() / save_html() produce a standalone snippet with no external dependency.

Parameters:
  • words (list) – (word, weight) pairs, expected in descending weight order.

  • title (str, optional) – Caption shown above the cloud.

save_html(name)[source]#

Write the cloud to a standalone .html file.

to_html(min_size=12, max_size=46)[source]#

Render the cloud as a self-contained HTML string.

gismap.gismo.make_gismo(lab, vectorizer_parameters=None)[source]#

Makes a gismo out of a lab.

Parameters:
  • lab (LabMap) – Lab that contains publications.

  • vectorizer_parameters (dict) – Overriding parameters for the Countvectorizer of the gismo.

Returns:

gismo – Gismo of the lab.

Return type:

Gismo

gismap.gismo.make_post_publi(lab)[source]#

Hook to turn publication key stored in a corpus into actual publication.

Parameters:

lab (LabMap) – Lab that contains the corpus publications.

Return type:

callable

gismap.gismo.publication_author_keys(pub)[source]#

Author keys of a publication (the tokens of the author-side embedding).

gismap.gismo.publication_text(pub)[source]#

Text used for keyword extraction: title plus the first available abstract.

Parameters:

pub (Publication) – A publication (typically a SourcedPublication).

Return type:

str

class gismap.search.Search(gismo, action_list, post=None, corrector=True)[source]#

Builds a gismo search engine.

Parameters:
  • gismo (Gismo) – Gismo to use.

  • action_list (list) – List of actions to perform.

  • post (callable, optional) – Output transformation.

  • corrector (Bool, default=True) – Implement word correction.

class gismap.search.SearchAction(name=None, post=None)[source]#

Base class for extracting search results from a Gismo.

Subclasses should implement process() to define how to extract results from the gismo.

Parameters:
  • name (str, optional) – Name of this action (used as key in results dict).

  • post (callable, optional) – Post-processing function applied to results.

process(gismo)[source]#

Extract results from the gismo. Must be implemented by subclasses.

Parameters:

gismo (Gismo) – The gismo to query.

Return type:

Results (type depends on subclass).

run(gismo)[source]#

Execute the action and apply post-processing.

Parameters:

gismo (Gismo) – The gismo to query.

Return type:

Post-processed results.

class gismap.search.SearchDocuments(name='articles', post=None, k=5)[source]#

Gives k best covering articles.

process(gismo)[source]#

Extract results from the gismo. Must be implemented by subclasses.

Parameters:

gismo (Gismo) – The gismo to query.

Return type:

Results (type depends on subclass).

class gismap.search.SearchFeatures(name='keywords', post=None)[source]#

Gives best keywords.

process(gismo)[source]#

Extract results from the gismo. Must be implemented by subclasses.

Parameters:

gismo (Gismo) – The gismo to query.

Return type:

Results (type depends on subclass).

class gismap.search.SearchLandmarks(name='landmarks', post=None, lmks=None)[source]#

Gives best landmarks.

process(gismo)[source]#

Extract results from the gismo. Must be implemented by subclasses.

Parameters:

gismo (Gismo) – The gismo to query.

Return type:

Results (type depends on subclass).

gismap.search.l2t(lis)[source]#
Parameters:

lis (list) – List of text.

Returns:

Concatenation, comma-separated.

Return type:

str

gismap.search.p2t(publis)[source]#
Parameters:

publis (list) – List of publications

Returns:

Publications converted in text and concatenated.

Return type:

str

gismap.search.publi_to_html(publi)[source]#

Convert a publication to an HTML list item.

Parameters:

publi (Publication) – Publication to convert.

Returns:

HTML list item string.

Return type:

str

gismap.search.publis_to_html(publis)[source]#

Convert a list of publications to an HTML unordered list.

Parameters:

publis (list) – List of publications.

Returns:

HTML unordered list string.

Return type:

str

gismap.search.search_to_html(res)[source]#
Parameters:

res (dict) – Raw results of search.

Returns:

HTML representation of the results.

Return type:

str

gismap.search.search_to_text(res)[source]#
Parameters:

res (dict) – Raw results of search.

Returns:

Text representation of the results.

Return type:

str