Skip to content

question about adding namespaces #661

@Luke-ebbis

Description

@Luke-ebbis

Dear developers, I have been exploring the usage of this tool in my data transformation pipeline. If find it to be quite useful in forming RDF documents. However, I am not sure on how to specify the namespace of my graphs I produce. For example:

clusterA(a, p1) .
clusterA(a, p2) .
clusterA(a, p3) .
clusterA(a, p4) .
clusterA(a, p0) .

clusterA(b, p100) .
clusterA(b, p101) .

clusterB(A, p0) .
clusterB(A, p1) .

clusterB(B, p2) .
clusterB(B, p100) .
% cluster(?name, ?proteins)


@prefix up: <http://purl.uniprot.org/uniprot/> .
@prefix base: <http://example.com/clustering/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .


cluster1(IRI(?X), IRI(?y)) :- clusterB(?X, ?y).
cluster2(IRI(?X), IRI(?y)) :- clusterA(?X, ?y) .

% When a Cluster in set X is connected to a Cluster in set Y.
isConnected(?clusterNameX, ?p, ?clusterNameY) :- 
    cluster1(?clusterNameX, ?p) , % it must be in X
    cluster2(?clusterNameY, ?p) . % it must be in Y.

% When a cluster X has a connection to Y.
hasOutConnection(?X, ?Y) :-
    isConnected(?X, ?p, ?Y) . 

% When a cluster X has n connections to Y.
hasOutConnectionCount(?X, ?Y, #count(?p)) :-
    isConnected(?X, ?p, ?Y) .

% When a cluster X has n connections to Y.
hasTotalConnections(?X, #sum(?count, ?p)) :-
    hasOutConnectionCount(?X, ?p, ?count) .

hasWeightedConnection(?X, ?Y, ?w) :-
    hasOutConnectionCount(?X, ?Y, ?count) ,
    hasTotalConnections(?X, ?total),
    ?w = ?count / double(?total).    

hasConnection(?X, ?Y) :-
    hasOutConnection(?X, ?Y),
    hasOutConnection(?Y, ?X) .


% Exporting our analysis to RDF

cluster(?X, ?p, clusterA) :-
    cluster1(?X, ?p) .
cluster(?X, ?p, clusterB) :-
    cluster2(?X, ?p) .

up:Protein(?X, ?p, ?T) :- 
    cluster(?X, ?p, ?T) ,
    ?p = concat("-", str(?p)) .

graph(?X, base:hasMember, ?p) :- 
    cluster(?X, ?p, ?T).
graph(?p, base:memberOf, ?X) :- 
    cluster(?X, ?p, ?T).
graph(?X, base:cluster, ?T) :- 
    cluster(?X, ?p, ?T).
graph(?p, rdf:type, up:Protein) :- 
    up:Protein(?X, ?p, ?T). 
graph(?X, base:connectsTo, ?Y) :- 
    hasOutConnection(?X, ?Y) .
graph(?X, base:connectsTo, ?Y) :- 
    hasOutConnection(?Y, ?X) .
graph(?key, rdf:type, rdf:Statement),
graph(?key, rdf:predicate, base:hasOutConnection),
graph(?key, rdf:object, ?Y),
graph(?key, rdf:value, double(?w)),
graph(?key, rdf:subject, ?X),:-
    hasOutConnection(?X, ?Y) ,
    hasWeightedConnection(?X, ?Y, ?w),
    ?key = f"http://example.com/clustering/{?Y}-{?Y}", 
    ?key = uri(?key).

@export graph :- rdf{resource="rdf.ttl"}.
@export hasTotalConnections :-
    csv{resource="connectivity.csv"} .
@export hasWeightedConnection :-
    csv{resource="hasWeightedConnection.csv", 
    format=(any,any,double)} .

Then I get the error that complex terms are not supported. Is there a better way to do this? I am sure its possible but I cannot find it in the documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions