<commit_before>
from wadl2rst.nodes.base import BaseNode


class RepresentationNode(BaseNode):

    def to_example(self):
        code_node = self.find_first("xsdxt:sample")
        if code_node is None:
            return None

        char_node = code_node.find_first("char")
        if char_node is None:
            return None

        try:
            doc_node = self.find_one_of(["wadl:doc", "doc"])
            title = doc_node.attributes.get("title", None)
        except ValueError, e:
            title = None

        code_text = char_node.attributes['text']

        media_type = self.attributes.get('mediaType', None)
        media_type = mimetype_translation.get(media_type, "JSON")

        # TODO(auggy): modify the last word to match the samples in the nova repo

        return {
            "title": title,
            "type": media_type,
            "code": code_text
        }


mimetype_translation = {
    "application/json": "JSON",
    "application/xml": "XML"
}<commit_msg>shorten api_samples filenames to match compute api<commit_after>
from wadl2rst.nodes.base import BaseNode
import re

class RepresentationNode(BaseNode):

    def to_example(self):
        code_node = self.find_first("xsdxt:sample")
        if code_node is None:
            return None

        char_node = code_node.find_first("char")
        if char_node is None:
            return None

        try:
            doc_node = self.find_one_of(["wadl:doc", "doc"])
            title = doc_node.attributes.get("title", None)
        except ValueError, e:
            title = None

        code_text = char_node.attributes['text']

        media_type = self.attributes.get('mediaType', None)
        media_type = mimetype_translation.get(media_type, "JSON")

        # modify the last word to match the samples in the nova repo
        chopped_text = re.sub(pattern=r'\w{4}(?=(.json)$)',repl='', string=code_text)

        return {
            "title": title,
            "type": media_type,
            "code": chopped_text
        }


mimetype_translation = {
    "application/json": "JSON",
    "application/xml": "XML"
}
{'fraction_non_alphanumeric': 0.10791705937794534, 'fraction_numerical': 0.001413760603204524, 'mean_word_length': 2.296583850931677, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7199580', 'n_tokens_mistral': 647, 'n_tokens_neox': 625, 'n_words': 150}