コード例 #1
0
def update_annotation_textual_body(identifier: str,
                                   value: str = None,
                                   format_: str = None,
                                   language: str = None):
    """Return a mutation for updating an AnnotationTextualBody.

    Returns:
        A GraphQL Mutation to update an AnnotationTextualBody in the Trompa CE
    """
    check_required_args(identifier=identifier)
    if language and language.lower() not in SUPPORTED_LANGUAGES:
        raise UnsupportedLanguageException(language)

    params = {"identifier": identifier, "value": value, "format": format_}
    params = filter_none_args(params)

    if language is not None:
        params["language"] = StringConstant(language.lower())

    return format_mutation(mutationname="UpdateAnnotationTextualBody",
                           args=params)
コード例 #2
0
def update_rating(identifier: str,
                  *,
                  creator: str = None,
                  ratingvalue: int = None,
                  bestrating: int = None,
                  worstrating: int = None,
                  ratingexplanation: str = None,
                  additionaltype: str = None):

    params = {
        "identifier": identifier,
        "creator": creator,
        "ratingValue": ratingvalue,
        "bestRating": bestrating,
        "worstRating": worstrating,
        "ratingExplanation": ratingexplanation,
        "additionalType": additionaltype
    }

    params = filter_none_args(params)
    return format_mutation(mutationname="UpdateRating", args=params)
コード例 #3
0
def mutation_create_musicplaylist(*,
                                  title: str,
                                  contributor: str,
                                  creator: str,
                                  source: str,
                                  format_: str,
                                  name: str = None,
                                  language: str = None,
                                  num_tracks: int = None):
    """Returns a mutation for creating a MusicPlaylist object.

    Arguments:
        {musicplaylist_args}

    Returns:
        The string for the mutation for creating the MusicPlaylist.
    """

    if "/" not in format_:
        raise NotAMimeTypeException(format_)

    if language is not None and language not in SUPPORTED_LANGUAGES:
        raise UnsupportedLanguageException(language)

    args = {
        "title": title,
        "contributor": contributor,
        "creator": creator,
        "source": source,
        "format": format_,
        "name": name,
        "numTracks": num_tracks
    }
    if language is not None:
        args["language"] = StringConstant(language.lower())

    args = filter_none_args(args)

    return format_mutation("CreateMusicPlaylist", args)
コード例 #4
0
def update_annotation(identifier: str,
                      target: str = None,
                      motivation: Union[AnnotationSchemaMotivation,
                                        str] = None,
                      body: str = None,
                      creator: str = None):
    """Return a mutation for updating an Annotation.

    Returns:
        A GraphQL Mutation to create an Annotation in the Trompa CE
    """
    check_required_args(identifier=identifier)
    params = {
        "identifier": identifier,
        "target": target,
        "motivation": motivation,
        "body": body,
        "creator": creator
    }
    params = filter_none_args(params)

    return format_mutation(mutationname="UpdateAnnotation", args=params)
コード例 #5
0
def create_defined_term(*, creator: str, termcode: str, additionaltype: List[str], image: str = None):
    """Return a mutation for making a DefinedTerm.
    A :schema:`DefinedTerm` is a word, name, acronym, phrase, etc. with a formal definition.
    It is part of a DefinedTermSet.

    Arguments:
        {definedterm_args}

    Returns:
        A GraphQL Mutation to create a DefinedTerm in the Trompa CE
    """
    check_required_args(creator=creator, termcode=termcode, additionaltype=additionaltype)
    additionaltype = _verify_additional_type(additionaltype)

    params = {"additionalType": additionaltype,
              "creator": creator,
              "termCode": termcode,
              "image": image}

    params = filter_none_args(params)

    return format_mutation(mutationname="CreateDefinedTerm", args=params)
コード例 #6
0
def update_defined_term(identifier: str, *, creator: str = None, termcode: str = None,
                        additionaltype: List[str] = None, image: str = None):
    """Return a mutation for updating a DefinedTerm.

    Arguments:
        identifier: The identifier of the DefinedTerm in the CE to be updated (:dcterms:`identifier`).
        {definedterm_args}

    Returns:
        A GraphQL Mutation to update a DefinedTerm in the Trompa CE
    """

    additionaltype = _verify_additional_type(additionaltype)
    params = {"identifier": identifier,
              "creator": creator,
              "termCode": termcode,
              "additionalType": additionaltype,
              "image": image}

    params = filter_none_args(params)

    return format_mutation(mutationname="UpdateDefinedTerm", args=params)
コード例 #7
0
def create_rating(*,
                  creator: str,
                  bestrating: int,
                  ratingvalue: int = None,
                  worstrating: int = None,
                  ratingexplanation: str = None,
                  additionaltype: str = None):
    """Return a mutation for making a Rating.
    A Rating (https://schema.org/Rating) is an evaluation on a numeric scale.

    Arguments:
        creator: a URI to the identity of the user who created this DefinedTerm
        bestrating: The highest value allowed in this rating system
        ratingvalue: The rating for the content.
        worstrating (optional): The lowest value allowed in this rating system. If worstRating is omitted, 1 is assumed.
        ratingexplanation (optional): A freeform text box describing why this rating was given
        additionaltype (optional): A schema.org additionalType used to categorise this Rating

    Returns:
        A GraphQL Mutation to create a Rating in the Trompa CE
    """

    check_required_args(creator=creator,
                        bestrating=bestrating,
                        ratingvalue=ratingvalue)

    params = {
        "creator": creator,
        "ratingValue": ratingvalue,
        "bestRating": bestrating,
        "worstRating": worstrating,
        "ratingExplanation": ratingexplanation,
        "additionalType": additionaltype
    }

    params = filter_none_args(params)

    return format_mutation(mutationname="CreateRating", args=params)
コード例 #8
0
def mutation_update_itemlist(identifier: str,
                             name: str = None,
                             creator: str = None,
                             itemlistorder: ItemListOrderType = None,
                             description: str = None,
                             contributor: str = None,
                             additionaltype: List[str] = None):
    """Returns a mutation for updating an ItemList object.
    (https://schema.org/ItemList)

    Arguments:
        identifier: The identifier of the ItemList in the CE to be updated.
        {itemlist_args}

    Returns:
        The string for the mutation for updating the ItemList.
    """
    if itemlistorder is not None and not isinstance(itemlistorder,
                                                    ItemListOrderType):
        raise trompace.exceptions.InvalidItemListOrderTypeException(
            itemlistorder)
    check_required_args(identifier=identifier)
    additionaltype = _verify_additional_type(additionaltype)

    args = {
        "identifier": identifier,
        "contributor": contributor,
        "name": name,
        "description": description,
        "creator": creator,
        "additionalType": additionaltype,
    }
    if itemlistorder is not None:
        args["itemListOrder"] = StringConstant(itemlistorder)

    args = filter_none_args(args)

    return format_mutation("UpdateItemList", args)
コード例 #9
0
def update_annotation_motivation(
        identifier: str,
        creator: str,
        title: str,
        description: str,
        broader_schema: AnnotationSchemaMotivation = None,
        broader_url: str = None):
    """Return a mutation for updating an Annotation motivation

    """
    check_required_args(identifier=identifier)
    params = {
        "identifier": identifier,
        "creator": creator,
        "title": title,
        "description": description,
        "broaderUrl": broader_url,
    }
    if broader_schema:
        params["broaderMotivation"] = StringConstant(broader_schema.name)
    params = filter_none_args(params)
    return format_mutation(mutationname="UpdateAnnotationCEMotivation",
                           args=params)
コード例 #10
0
def create_annotation_ce_target(creator: str,
                                field: str = None,
                                fragment: str = None):
    """Return a mutation for making an AnnotationCETarget.
    An AnnotationCETarget is a node that can be used for a
    web Annotation (https://www.w3.org/TR/annotation-model)
    as the target field, when the target refers to a node that already exists in the CE

    Arguments:
        creator: a URI to the identity of the user who created this AnnotationCETaraget
        field (optional): the field of the node `target` that contains the URL to the target item
        fragment (optional): If the target is a fragment, the value to be appended to the URL in field

    Returns:
        A GraphQL Mutation to create an AnnotationCETarget in the Trompa CE
    """

    check_required_args(creator=creator)

    params = {"creator": creator, "field": field, "fragment": fragment}
    params = filter_none_args(params)

    return format_mutation(mutationname="CreateAnnotationCETarget",
                           args=params)
コード例 #11
0
def create_defined_term_set(*, creator: str, name: str, additionaltype: List[str], broader_url: str = None,
                            broader_schema: annotation.AnnotationSchemaMotivation = None, image: str = None):
    """Return a mutation for making a DefinedTermSet.
    A :schema:`DefinedTermSet` is a group of defined terms, e.g. categories or labels.

    Arguments:
        {definedtermset_args}

    Returns:
        A GraphQL Mutation to create a DefinedTermSet in the Trompa CE
    """

    check_required_args(creator=creator, name=name, additionaltype=additionaltype)
    additionaltype = _verify_additional_type(additionaltype)

    params = {"additionalType": additionaltype,
              "creator": creator,
              "name": name,
              "broaderUrl": broader_url,
              "image": image}
    if broader_schema is not None:
        params["broaderMotivation"] = StringConstant(broader_schema.name)
    params = filter_none_args(params)
    return format_mutation(mutationname="CreateDefinedTermSet", args=params)
コード例 #12
0
ファイル: person.py プロジェクト: trompamusic/trompace-client
def mutation_create_person(*,
                           title: str,
                           contributor: str,
                           creator: str,
                           source: str,
                           format_: str,
                           language: str = None,
                           name: str = None,
                           family_name: str = None,
                           given_name: str = None,
                           gender: str = None,
                           birth_date: str = None,
                           death_date: str = None,
                           description: str = None,
                           image: str = None,
                           publisher: str = None,
                           honorific_prefix: str = None,
                           honorific_suffix: str = None,
                           job_title: str = None):
    """Returns a mutation for creating a Person

    Args:
        {person_args}
    Returns:
        The string for the mutation for creating the person.
    Raises:
        UnsupportedLanguageException: if ``language`` is not one of the supported languages.
        ValueError: if ``gender`` is not a value supported by the CE
        NotAMimeTypeException: if ``format_`` is not a valid mimetype.
    """

    check_required_args(title=title,
                        contributor=contributor,
                        creator=creator,
                        source=source,
                        format_=format_)
    if language and language.lower() not in SUPPORTED_LANGUAGES:
        raise UnsupportedLanguageException(language)

    if gender and gender.lower() not in SUPPORTED_GENDER:
        raise ValueError(f"unexpected value for gender: {gender}")

    if "/" not in format_:
        raise NotAMimeTypeException(format_)

    args = {
        "title": title,
        "contributor": contributor,
        "creator": creator,
        "source": source,
        "format": format_,
        "name": name,
        "familyName": family_name,
        "givenName": given_name,
        "description": description,
        "image": image,
        "publisher": publisher,
        "honorificPrefix": honorific_prefix,
        "honorificSuffix": honorific_suffix,
        "jobTitle": job_title
    }
    if gender is not None:
        args["gender"] = StringConstant(gender.lower())
    if language is not None:
        args["language"] = StringConstant(language.lower())
    if birth_date is not None:
        args["birthDate"] = _Neo4jDate(birth_date)
    if death_date is not None:
        args["deathDate"] = _Neo4jDate(death_date)

    args = filter_none_args(args)

    return format_mutation("CreatePerson", args)
コード例 #13
0
def mutation_update_media_object(identifier: str,
                                 *,
                                 name: str = None,
                                 title: str = None,
                                 description: str = None,
                                 date: str = None,
                                 creator: str = None,
                                 contributor: str = None,
                                 format_: str = None,
                                 encodingformat: str = None,
                                 source: str = None,
                                 license: str = None,
                                 subject: str = None,
                                 url: str = None,
                                 contenturl: str = None,
                                 language: str = None,
                                 inlanguage: str = None):
    """Returns a mutation for updating a media object object.

    Arguments:
        identifier: The identifier of the media object in the CE to be updated.
        {mediaobject_args}

    Returns:
        The string for the mutation for updating the media object.

    Raises:
        Assertion error if the input language or inLanguage is not one of the supported languages.
    """
    if format_ is not None and "/" not in format_:
        raise NotAMimeTypeException(format_)

    if encodingformat is not None and "/" not in encodingformat:
        raise NotAMimeTypeException(encodingformat)

    if language is not None and language not in SUPPORTED_LANGUAGES:
        raise UnsupportedLanguageException(language)

    args = {
        "identifier": identifier,
        "name": name,
        "title": title,
        "description": description,
        "creator": creator,
        "contributor": contributor,
        "format": format_,
        "encodingFormat": encodingformat,
        "source": source,
        "subject": subject,
        "url": url,
        "contentUrl": contenturl,
        "license": license,
        "inLanguage": inlanguage,
    }
    if date:
        args["date"] = _Neo4jDate(date)
    if language:
        args["language"] = StringConstant(language.lower())

    args = filter_none_args(args)

    return format_mutation("UpdateMediaObject", args)
コード例 #14
0
def mutation_create_media_object(*,
                                 title: str,
                                 contributor: str,
                                 creator: str,
                                 source: str,
                                 format_: str,
                                 name: str = None,
                                 description: str = None,
                                 date: str = None,
                                 encodingformat: str = None,
                                 embedurl: str = None,
                                 url: str = None,
                                 contenturl: str = None,
                                 language: str = None,
                                 inlanguage: str = None,
                                 license: str = None):
    """Returns a mutation for creating a media object object.

    Arguments:
        {mediaobject_args}

    Returns:
        The string for the mutation for creating the media object.

    Raises:
        UnsupportedLanguageException if the input language is not one of the supported languages.
    """
    check_required_args(title=title,
                        contributor=contributor,
                        creator=creator,
                        source=source,
                        format_=format_)
    if language is not None and language not in SUPPORTED_LANGUAGES:
        raise UnsupportedLanguageException(language)

    if "/" not in format_:
        raise NotAMimeTypeException(format_)

    if encodingformat is not None and "/" not in encodingformat:
        raise NotAMimeTypeException(encodingformat)

    args = {
        "title": title,
        "contributor": contributor,
        "creator": creator,
        "source": source,
        "format": format_,
        "name": name,
        "description": description,
        "encodingFormat": encodingformat,
        "embedUrl": embedurl,
        "url": url,
        "license": license,
        "contentUrl": contenturl,
        "inLanguage": inlanguage,
    }

    if date is not None:
        args["date"] = _Neo4jDate(date)
    if language is not None:
        args["language"] = StringConstant(language.lower())

    args = filter_none_args(args)

    return format_mutation("CreateMediaObject", args)