1
1
from neomodel import (
2
2
StructuredNode ,
3
+ StructuredRel ,
3
4
StringProperty ,
4
5
UniqueIdProperty ,
5
6
RelationshipTo ,
@@ -13,6 +14,8 @@ class Place(StructuredNode):
13
14
"""
14
15
Base class for all places. Adds the 'Place' label to all subclasses.
15
16
"""
17
+ # __abstract_node__ = True
18
+
16
19
uid = UniqueIdProperty ()
17
20
name = StringProperty (required = True ) # Common property for all places
18
21
coordinates = PointProperty (crs = "wgs-84" ) # Spatial property for geographic coordinates
@@ -25,28 +28,43 @@ class State(Place):
25
28
abbreviation = StringProperty (required = True , unique_index = True ) # e.g., "IL"
26
29
27
30
# Relationships
28
- capital = RelationshipTo ("City" , "HAS_CAPITAL" , cardinality = One ) # A state has one capital city
29
- counties = RelationshipTo ("County" , "HAS_COUNTY" ) # A state contains multiple counties
31
+ cities = RelationshipTo ("City" , "HAS_CITY" )
32
+ counties = RelationshipTo ("County" , "HAS_COUNTY" )
30
33
31
34
def __repr__ (self ):
32
35
return f"<State { self .name } >"
33
36
34
37
35
38
class County (Place ):
36
39
# Relationships
37
- state = RelationshipFrom ("State" , "HAS_COUNTY" ) # A county belongs to a state
38
- cities = RelationshipTo ("City" , "HAS_CITY" ) # A county contains multiple cities
40
+ state = RelationshipFrom ("State" , "HAS_COUNTY" )
41
+ cities = RelationshipTo ("City" , "HAS_CITY" )
39
42
40
43
def __repr__ (self ):
41
44
return f"<County { self .name } >"
42
45
43
46
44
47
class City (Place ):
45
- population = StringProperty () # Optional: population of the city
48
+ population = StringProperty ()
49
+
50
+ # Relationships
51
+ state = RelationshipFrom ("State" , "HAS_CITY" )
52
+ county = RelationshipFrom ("County" , "HAS_CITY" )
53
+
54
+ def __repr__ (self ):
55
+ return f"<City { self .name } >"
56
+
57
+
58
+ class Precinct (Place ):
59
+ """
60
+ Represents a precinct, which is a smaller administrative division within a city or county.
61
+ """
46
62
47
63
# Relationships
48
- state = RelationshipFrom ("State" , "HAS_CAPITAL" ) # A city can be the capital of a state
49
- county = RelationshipFrom ("County" , "HAS_CITY" ) # A city belongs to a county
64
+ city = RelationshipFrom ("City" , "HAS_PRECINCT" )
65
+ county = RelationshipFrom ("County" , "HAS_PRECINCT" )
66
+ agency = RelationshipTo ("Agency" , "SERVED_BY" ) # Connects Precinct to Agency
67
+ units = RelationshipTo ("Unit" , "PATROLLED_BY" ) # Connects Precinct to Unit
50
68
51
69
def __repr__ (self ):
52
- return f"<City { self .name } >"
70
+ return f"<Precinct { self .name } >"
0 commit comments