How to use the neomodel.ArrayProperty function in neomodel

To help you get started, we’ve selected a few neomodel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github neo4j-contrib / neomodel / test / test_contrib / test_spatial_properties.py View on Github external
def test_array_of_points():
    """
    Tests that Arrays of Points work as expected.

    :return:
    """

    class AnotherLocalisableEntity(neomodel.StructuredNode):
        """
        A very simple entity with an array of locations
        """
        identifier = neomodel.UniqueIdProperty()
        locations = neomodel.ArrayProperty(neomodel.contrib.spatial_properties.PointProperty(crs='cartesian'))

    # Neo4j versions lower than 3.4.0 do not support Point. In that case, skip the test.
    check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')

    an_object = AnotherLocalisableEntity(locations=
                                         [neomodel.contrib.spatial_properties.NeomodelPoint((0.0,0.0)),
                                          neomodel.contrib.spatial_properties.NeomodelPoint((1.0,0.0))]).save()

    retrieved_object = AnotherLocalisableEntity.nodes.get(identifier=an_object.identifier)

    assert type(retrieved_object.locations) is list, "Array of Points definition failed."
    assert retrieved_object.locations == [neomodel.contrib.spatial_properties.NeomodelPoint((0.0,0.0)),
                                          neomodel.contrib.spatial_properties.NeomodelPoint((1.0,0.0))], \
        "Array of Points incorrect values."
github neo4j-contrib / neomodel / test / test_contrib / test_spatial_properties.py View on Github external
def test_array_of_points():
    """
    Tests that Arrays of Points work as expected.

    :return:
    """

    class AnotherLocalisableEntity(neomodel.StructuredNode):
        """
        A very simple entity with an array of locations
        """
        identifier = neomodel.UniqueIdProperty()
        locations = neomodel.ArrayProperty(neomodel.contrib.spatial_properties.PointProperty(crs='cartesian'))

    # Neo4j versions lower than 3.4.0 do not support Point. In that case, skip the test.
    check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')

    an_object = AnotherLocalisableEntity(locations=
                                         [neomodel.contrib.spatial_properties.NeomodelPoint((0.0,0.0)),
                                          neomodel.contrib.spatial_properties.NeomodelPoint((1.0,0.0))]).save()

    retrieved_object = AnotherLocalisableEntity.nodes.get(identifier=an_object.identifier)

    assert type(retrieved_object.locations) is list, "Array of Points definition failed."
    assert retrieved_object.locations == [neomodel.contrib.spatial_properties.NeomodelPoint((0.0,0.0)),
                                          neomodel.contrib.spatial_properties.NeomodelPoint((1.0,0.0))], \
        "Array of Points incorrect values."
github mostafa / grest / grest / models.py View on Github external
if the user has defined validation rules,
        return that, otherwise construct a set of
        predefined rules and return it.

        All internal GRest methods should use this property.
        """

        if hasattr(self, "__validation_rules__"):
            if len(self.__validation_rules__) > 0:
                # there is a set of user-defined validation rules
                return self.__validation_rules__

        model_types = [
            StringProperty, DateTimeProperty, DateProperty,
            EmailProperty, BooleanProperty, UniqueIdProperty,
            ArrayProperty, IntegerProperty, JSONProperty
        ]

        model_mapping = {
            IntegerProperty: fields.Int,
            StringProperty: fields.Str,
            BooleanProperty: fields.Bool,
            DateTimeProperty: fields.DateTime,
            DateProperty: fields.Date,
            EmailProperty: fields.Email,
            ArrayProperty: fields.List,
            JSONProperty: fields.Dict,
            UniqueIdProperty: fields.UUID
        }

        name = 0
        value = 1
github romaintha / twitter / twitter / models.py View on Github external
import datetime

import neomodel


class Tweet(neomodel.StructuredNode):
    id_str = neomodel.StringProperty(unique_index=True, required=True)
    created_at = neomodel.DateTimeProperty(required=False)
    modified = neomodel.DateTimeProperty(required=False)
    retweeted = neomodel.BooleanProperty(required=False)
    retweet_id_str = neomodel.StringProperty(required=False, default='')
    reply_id_str = neomodel.StringProperty(required=False, default='')
    quote_id_str = neomodel.StringProperty(required=False, default='')
    mention_ids_str = neomodel.ArrayProperty(required=False, default=[])
    text = neomodel.StringProperty(required=False)
    coordinates = neomodel.ArrayProperty(required=False, default=[])
    lang = neomodel.StringProperty(required=False)
    features = neomodel.JSONProperty(required=False, default={})

    retweets = neomodel.RelationshipTo('Tweet', 'RETWEETS')
    mentions = neomodel.RelationshipTo('User', 'MENTIONS')
    replies = neomodel.RelationshipTo('Tweet', 'REPLIES')
    tags = neomodel.RelationshipTo('Hashtag', 'TAGS')
    contains = neomodel.RelationshipTo('Link', 'CONTAINS')
    quotes = neomodel.Relationship('Tweet', 'QUOTES')

    def save(self):
        self.modified = datetime.datetime.now()
        super(Tweet, self).save()
github romaintha / twitter / twitter / models.py View on Github external
def save(self):
        self.modified = datetime.datetime.now()
        super(Tweet, self).save()


class User(neomodel.StructuredNode):
    id_str = neomodel.StringProperty(unique_index=True, required=True)
    name = neomodel.StringProperty(required=False)
    screen_name = neomodel.StringProperty(required=False)
    followers_count = neomodel.IntegerProperty(required=False)
    friends_count = neomodel.IntegerProperty(required=False)
    modified = neomodel.DateTimeProperty(required=False)
    created_at = neomodel.DateTimeProperty(required=False)
    description = neomodel.StringProperty(required=False)
    location = neomodel.StringProperty(required=False)
    coordinates = neomodel.ArrayProperty(required=False, default=[])
    time_zone = neomodel.StringProperty(required=False)
    url = neomodel.StringProperty(required=False)
    lang = neomodel.StringProperty(required=False)

    follows = neomodel.RelationshipTo('User', 'FOLLOWS')
    posts = neomodel.RelationshipTo('Tweet', 'POSTS')

    def save(self):
        self.modified = datetime.datetime.now()
        super(User, self).save()


class Hashtag(neomodel.StructuredNode):
    text = neomodel.StringProperty(unique_index=True, required=True)
github romaintha / twitter / twitter / models.py View on Github external
import datetime

import neomodel


class Tweet(neomodel.StructuredNode):
    id_str = neomodel.StringProperty(unique_index=True, required=True)
    created_at = neomodel.DateTimeProperty(required=False)
    modified = neomodel.DateTimeProperty(required=False)
    retweeted = neomodel.BooleanProperty(required=False)
    retweet_id_str = neomodel.StringProperty(required=False, default='')
    reply_id_str = neomodel.StringProperty(required=False, default='')
    quote_id_str = neomodel.StringProperty(required=False, default='')
    mention_ids_str = neomodel.ArrayProperty(required=False, default=[])
    text = neomodel.StringProperty(required=False)
    coordinates = neomodel.ArrayProperty(required=False, default=[])
    lang = neomodel.StringProperty(required=False)
    features = neomodel.JSONProperty(required=False, default={})

    retweets = neomodel.RelationshipTo('Tweet', 'RETWEETS')
    mentions = neomodel.RelationshipTo('User', 'MENTIONS')
    replies = neomodel.RelationshipTo('Tweet', 'REPLIES')
    tags = neomodel.RelationshipTo('Hashtag', 'TAGS')
    contains = neomodel.RelationshipTo('Link', 'CONTAINS')
    quotes = neomodel.Relationship('Tweet', 'QUOTES')

    def save(self):
        self.modified = datetime.datetime.now()
        super(Tweet, self).save()


class User(neomodel.StructuredNode):
github mostafa / grest / grest / models.py View on Github external
return self.__validation_rules__

        model_types = [
            StringProperty, DateTimeProperty, DateProperty,
            EmailProperty, BooleanProperty, UniqueIdProperty,
            ArrayProperty, IntegerProperty, JSONProperty
        ]

        model_mapping = {
            IntegerProperty: fields.Int,
            StringProperty: fields.Str,
            BooleanProperty: fields.Bool,
            DateTimeProperty: fields.DateTime,
            DateProperty: fields.Date,
            EmailProperty: fields.Email,
            ArrayProperty: fields.List,
            JSONProperty: fields.Dict,
            UniqueIdProperty: fields.UUID
        }

        name = 0
        value = 1

        for field in self.defined_properties().items():
            if field[name] not in self.__validation_rules__:
                if type(field[value]) in model_types:
                    if isinstance(field[value], ArrayProperty):
                        if field[value].unique_index:
                            # what it contains: Array of *String*
                            container = model_mapping[
                                type(field[value].unique_index)]
                        else: