Twin – I hope you succeded with your Query.
I used a similar scheme to »calibrate« the ruby-client activeOrient. A
small Item is missing, perhaps someone can provide some assistance.
This is the schema:
Vertexes: State, City, Street
Properties: State.name, City.name, City.state(Linkset) , Street.name
Edge: connect
Streets connect several Cities through the C-Edge
I found a solution involving a database query followed by ruby-statements,
I want to compare this with a pure Database-Query-Solution.
This is what I am doing in ActiveOrient:
read_german_cities_and_states_fom_wikipedia.each do |city,state|
state = State.update_or_create( where: { name: state }).first
city = City.create name: city, state: state.link
end
cities_rids = City.all.map &:link # generate an array of rid's
from the City-Class
read_german_street_names.each_with_index do |street, i|
street_record = Street.create name: street
count = i
cities = Array.new
while count < cities_rids.size && cities.size < 5 do
cities << cities_rids[count]
count = count + i
end
C.create_edge :from => street_record, :to => cities
end
This code initializes the database with a maximum of 4 cities which are
bound via C to a street.
Now I want to display all Streets which pass a certain state.
In ruby this is done via
128 State.all.each do |state|
# iterate over all states
129 streets= Street.all.map do |street |
# iterate over all streets
130 if street.connects.in.detect{|x| x.state == state }
# street.connects.in is the array of associated cities
131 street.name + " verbindet " + street.connects.in.map(
&:name ).join('; ')
132 end
133 end.compact
# remove all items without a match
134 unless streets.empty?
135 puts "..................................."
136 puts state.name
137 puts "..................................."
138 puts streets.join("\n")
139 end
140 end
which results in
...................................
Vogtland
...................................
Rosenstraße verbindet Alsdorf; Annaburg; Auerbach; Bad Breisig; Bad
Herrenalb
Kastanienweg verbindet Auerbach; Bad Liebenzell; Barntrup; Blomberg; Bünde
...................................
Mecklenburg-Vorp.
...................................
Eichenstraße verbindet Bad Doberan; Baden-Baden; Boppard; Creußen;
Eibenstock
Südstraße verbindet Bad Homburg vor der Höhe; Bergen auf Rügen; Bürgel;
Ebeleben; Frechen
Heinrich-Heine-Straße verbindet Bad Münder am Deister; Boizenburg/ Elbe;
Dingelstädt; Forchheim; Gräfenthal
Gerhart-Hauptmann-Straße verbindet Bad Sülze; Burg Stargard; Erkelenz;
Grafenau; Hof
...................................
and so on
This works with small dataset-sizes, but obviously not if a large number of
records has to process.
Then a pure-database-query-based solution is required.
How to proceed?
I will include this in the example-section of activeOrient.
--
---
You received this message because you are subscribed to the Google Groups
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.