機械翻訳について

「カスタム・アルゴリズム(PGX)」インタプリタ

カスタム・アルゴリズム(PGX)インタプリタを使用すると、Graph Studioのノートブック段落に独自のカスタムPGXグラフ・アルゴリズムを作成できます。

カスタム・アルゴリズム(PGX)の段落は%custom-algorithm-pgxで始まり、カスタム・グラフ・アルゴリズムはJava構文を使用して記述できます。 詳細は、JavadocのPGXアルゴリズムAPIを参照してください。

カスタム・アルゴリズム(PGX)段落を実行すると、アルゴリズムがコンパイルされます。 次に、コンパイルされたアルゴリズムをJava (PGX)またはPython (PGX)の段落で使用できます。

ヒント:

ノートブックの段落の下部にカーソルを置き、custom_algorithm_pgx_icon「CUSTOM-ALGORITHM-PGX段落の追加」アイコンをクリックして、ノートブックで即座にカスタム・アルゴリズム(PGX)段落を開くことができます。

たとえば、次のグラフ・アルゴリズムについて考えてみます:

%custom-algorithm-pgx
package oracle.pgx.algorithms;
 
import oracle.pgx.algorithm.annotations.GraphAlgorithm;
import oracle.pgx.algorithm.PgxGraph;
import oracle.pgx.algorithm.VertexProperty;
import oracle.pgx.algorithm.annotations.Out;
 
@GraphAlgorithm
public class IndegreeCentrality {
  public void indegreeCentrality(PgxGraph g, @Out VertexProperty<Integer> indegreeCentrality) {
    g.getVertices().forEach(n ->
        indegreeCentrality.set(n, (int) n.getInDegree())
    );
  }
}

前述のコードを実行した後、次のように、コンパイル済アルゴリズム(indegreeCentrality)をJava (PGX)またはPython (PGX)の段落に統合できます:

var graph = session.getGraph("HR_GRAPH")
var centrality = graph.createVertexProperty(PropertyType.INTEGER, "centrality")
var algorithm = session.getCompiledProgram("indegreeCentrality")
algorithm.run(graph, centrality)
graph.queryPgql("SELECT x.centrality, x.last_name FROM MATCH (x:employees) ORDER BY x.centrality DESC LIMIT 10").print(out,10,0)
graph = session.get_graph("HR_GRAPH")
centrality = graph.create_vertex_property("integer", "centrality")
algorithm = session.get_compiled_program("indegreeCentrality")
algorithm.run(graph, centrality)
graph.query_pgql("SELECT x.centrality, x.last_name FROM MATCH (x:employees) ORDER BY x.centrality DESC LIMIT 10").print()

グラフ問合せでは、次の出力が生成されます:

+------------------------+
| centrality | last_name |
+------------------------+
| 14         | King      |
| 9          | Kaufling  |
| 8          | Weiss     |
| 8          | Vollman   |
| 8          | Fripp     |
| 8          | Mourgos   |
| 7          | Kochhar   |
| 6          | Zlotkey   |
| 6          | Russell   |
| 6          | Cambrault |
+------------------------+

詳細は、「Oracle Databaseプロパティ・グラフのグラフ開発者ガイド」「カスタムPGXグラフ・アルゴリズムの使用」を参照してください。

また、サポートされているグラフ組込みアルゴリズムの詳細は、「GitHubの組込みアルゴリズム」を参照してください。