You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2020/01/09 11:48:05 UTC
[tinkerpop] 10/13: added rdf/. Super easy. FlatMapInitial is used
to wrap FlatMap functions that can serve as initials so we don't have to
duplicate code.
This is an automated email from the ASF dual-hosted git repository.
spmallette pushed a commit to branch 4.0-dev
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 4ac1cb896126f54eeb334667d4bfbd0ff3d25b62
Author: Marko A. Rodriguez <ok...@gmail.com>
AuthorDate: Mon Apr 29 16:31:43 2019 -0600
added rdf/. Super easy. FlatMapInitial is used to wrap FlatMap functions that can serve as initials so we don't have to duplicate code.
---
.../bytecode/compiler/BytecodeCompiler.java | 6 ++---
.../machine/function/initial/FlatMapInitial.java | 9 +++----
.../tinkerpop/machine/structure/rdf/TQuad.java | 27 ++++++++++++++++++++
.../machine/structure/rdf/TStatement.java | 28 +++++++++++++++++++++
.../tinkerpop/machine/structure/rdf/TStore.java | 28 +++++++++++++++++++++
.../tinkerpop/machine/structure/rdf/TTriple.java | 29 ++++++++++++++++++++++
6 files changed, 118 insertions(+), 9 deletions(-)
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/bytecode/compiler/BytecodeCompiler.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/bytecode/compiler/BytecodeCompiler.java
index 07b49ed..eca364f 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/bytecode/compiler/BytecodeCompiler.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/bytecode/compiler/BytecodeCompiler.java
@@ -19,7 +19,6 @@
package org.apache.tinkerpop.machine.bytecode.compiler;
import org.apache.tinkerpop.machine.bytecode.Bytecode;
-import org.apache.tinkerpop.machine.bytecode.BytecodeUtil;
import org.apache.tinkerpop.machine.bytecode.Instruction;
import org.apache.tinkerpop.machine.function.CFunction;
import org.apache.tinkerpop.machine.function.initial.FlatMapInitial;
@@ -37,8 +36,9 @@ public interface BytecodeCompiler {
final List<CFunction<C>> functions = new ArrayList<>();
for (final Instruction<C> instruction : bytecode.getInstructions()) {
final CFunction function = this.compile(instruction);
- functions.add(functions.isEmpty() && bytecode.getParent().isEmpty() && function instanceof Initializing ?
- new FlatMapInitial<>(function.coefficient(), function.label(), (Initializing) function, BytecodeUtil.getTraverserFactory(bytecode).get()) : function);
+ functions.add(functions.isEmpty() && bytecode.getParent().isEmpty() && function instanceof Initializing ? // if this is the first function, then wrap it in an InitialFunction
+ new FlatMapInitial<>(function.coefficient(), function.label(), (Initializing) function) :
+ function);
}
return functions;
}
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/function/initial/FlatMapInitial.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/function/initial/FlatMapInitial.java
index 8b06567..2a2ca21 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/function/initial/FlatMapInitial.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/function/initial/FlatMapInitial.java
@@ -21,7 +21,7 @@ package org.apache.tinkerpop.machine.function.initial;
import org.apache.tinkerpop.machine.coefficient.Coefficient;
import org.apache.tinkerpop.machine.function.AbstractFunction;
import org.apache.tinkerpop.machine.function.InitialFunction;
-import org.apache.tinkerpop.machine.traverser.TraverserFactory;
+import org.apache.tinkerpop.machine.traverser.species.EmptyTraverser;
import java.util.Iterator;
@@ -31,17 +31,14 @@ import java.util.Iterator;
public final class FlatMapInitial<C, S> extends AbstractFunction<C> implements InitialFunction<C, S> {
private final Initializing<C, ?, S> function;
- private final TraverserFactory<C> traverserFactory;
-
- public FlatMapInitial(final Coefficient<C> coefficient, final String label, final Initializing<C, ?, S> function, final TraverserFactory<C> traverserFactory) {
+ public FlatMapInitial(final Coefficient<C> coefficient, final String label, final Initializing<C, ?, S> function) {
super(coefficient, label);
this.function = function;
- this.traverserFactory = traverserFactory;
}
@Override
public Iterator<S> get() {
- return this.function.apply(traverserFactory.create(this, null));
+ return this.function.apply(EmptyTraverser.instance());
}
}
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/rdf/TQuad.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/rdf/TQuad.java
new file mode 100644
index 0000000..a860491
--- /dev/null
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/rdf/TQuad.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.machine.structure.rdf;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public interface TQuad extends TTriple {
+
+ public String graph();
+}
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/rdf/TStatement.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/rdf/TStatement.java
new file mode 100644
index 0000000..f530eff
--- /dev/null
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/rdf/TStatement.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.machine.structure.rdf;
+
+import org.apache.tinkerpop.machine.structure.TTuple;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public interface TStatement extends TTuple<String,String> {
+
+}
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/rdf/TStore.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/rdf/TStore.java
new file mode 100644
index 0000000..98726f6
--- /dev/null
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/rdf/TStore.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.machine.structure.rdf;
+
+import org.apache.tinkerpop.machine.structure.Structure;
+import org.apache.tinkerpop.machine.structure.TSequence;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public interface TStore extends TSequence<TStatement>, Structure {
+}
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/rdf/TTriple.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/rdf/TTriple.java
new file mode 100644
index 0000000..e15e4d1
--- /dev/null
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/rdf/TTriple.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.machine.structure.rdf;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public interface TTriple extends TStatement {
+
+ public String subject();
+ public String predicate();
+ public String object();
+}