Generate Operations
These Operations are used for generating edges, elements and objects. They are always available.
This directed graph is used in all the examples on this page, except for GetWalks:
graph TD
1(1, count=3) -- count=3 --> 2
1 -- count=1 --> 4
2(2, count=1) -- count=2 --> 3
2 -- count=1 --> 4(4, count=1)
2 -- count=1 --> 5(5, count=3)
3(3, count=2) -- count=4 --> 4
GenerateElements
Generates elements from objects using provided generators. Javadoc
Example generating elements from Strings
Results:
Example generating elements from domain objects
{
"class" : "GenerateElements",
"input" : [ {
"class" : "uk.gov.gchq.gaffer.doc.operation.GenerateElementsExample$DomainObject1",
"a" : 1,
"c" : 1
}, {
"class" : "uk.gov.gchq.gaffer.doc.operation.GenerateElementsExample$DomainObject2",
"a" : 1,
"b" : 2,
"c" : 1
} ],
"elementGenerator" : {
"class" : "uk.gov.gchq.gaffer.doc.operation.GenerateElementsExample$DomainObjectGenerator"
}
}
g.GenerateElements(
element_generator=g.ElementGenerator(
class_name="uk.gov.gchq.gaffer.doc.operation.GenerateElementsExample$DomainObjectGenerator",
fields={'class': 'uk.gov.gchq.gaffer.doc.operation.GenerateElementsExample$DomainObjectGenerator'}
),
input=[
{'class': 'uk.gov.gchq.gaffer.doc.operation.GenerateElementsExample$DomainObject1', 'a': 1, 'c': 1},
{'class': 'uk.gov.gchq.gaffer.doc.operation.GenerateElementsExample$DomainObject2', 'a': 1, 'b': 2, 'c': 1}
]
)
Results:
GenerateObjects
Generates objects from elements using provided generators. Javadoc
Example generating Strings from elements
final GenerateObjects<String> operation = new GenerateObjects.Builder<String>()
.input(new Entity.Builder()
.group("entity")
.vertex(6)
.property("count", 1)
.build(),
new Edge.Builder()
.group("edge")
.source(5).dest(6).directed(true)
.property("count", 1)
.build())
.generator(new ObjectGenerator())
.build();
{
"class" : "GenerateObjects",
"input" : [ {
"class" : "Entity",
"group" : "entity",
"vertex" : 6,
"properties" : {
"count" : 1
}
}, {
"class" : "Edge",
"group" : "edge",
"source" : 5,
"destination" : 6,
"directed" : true,
"properties" : {
"count" : 1
}
} ],
"elementGenerator" : {
"class" : "ObjectGenerator"
}
}
g.GenerateObjects(
element_generator=g.ElementGenerator(
class_name="uk.gov.gchq.gaffer.doc.operation.generator.ObjectGenerator",
fields={'class': 'uk.gov.gchq.gaffer.doc.operation.generator.ObjectGenerator'}
),
input=[
g.Entity(
group="entity",
properties={'count': 1},
vertex=6
),
g.Edge(
group="edge",
properties={'count': 1},
source=5,
destination=6,
directed=True
)
]
)
Results:
Example generating domain objects from elements
final GenerateObjects<Object> operation = new GenerateObjects.Builder<>()
.input(new Entity.Builder()
.group("entity")
.vertex(6)
.property("count", 1)
.build(),
new Edge.Builder()
.group("edge")
.source(5).dest(6).directed(true)
.property("count", 1)
.build())
.generator(new DomainObjectGenerator())
.build();
{
"class" : "GenerateObjects",
"input" : [ {
"class" : "Entity",
"group" : "entity",
"vertex" : 6,
"properties" : {
"count" : 1
}
}, {
"class" : "Edge",
"group" : "edge",
"source" : 5,
"destination" : 6,
"directed" : true,
"properties" : {
"count" : 1
}
} ],
"elementGenerator" : {
"class" : "uk.gov.gchq.gaffer.doc.operation.GenerateObjectsExample$DomainObjectGenerator"
}
}
g.GenerateObjects(
element_generator=g.ElementGenerator(
class_name="uk.gov.gchq.gaffer.doc.operation.GenerateObjectsExample$DomainObjectGenerator",
fields={'class': 'uk.gov.gchq.gaffer.doc.operation.GenerateObjectsExample$DomainObjectGenerator'}
),
input=[
g.Entity(
group="entity",
properties={'count': 1},
vertex=6
),
g.Edge(
group="edge",
properties={'count': 1},
source=5,
destination=6,
directed=True
)
]
)
Results: