Skip to content

Commit

Permalink
misc, does not compile now
Browse files Browse the repository at this point in the history
  • Loading branch information
vporton committed Dec 12, 2019
1 parent bc4dd8d commit f24d985
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Victor Porton"
],
"dependencies": {
"pure-dependency-injector": "~>0.9.17",
"pure-dependency-injector": "~>0.9.18",
"struct-params": "~>1.1.0",
"rdf_dlang": "~master",
"ae": "~>0.0.2331",
Expand Down
4 changes: 3 additions & 1 deletion source/xmlboiler/core/data.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

module xmlboiler.core.data;

import std.conv;
import std.stdio;
import std.file;
Expand Down Expand Up @@ -71,12 +73,12 @@ struct Global {
}
}

Provider!(Global, RedlandWorldWithoutFinalize) globalProvider;
mixin StructParams!("GlobalProvidersParams", RedlandWorldWithoutFinalize, "world");
immutable GlobalProvidersParams.Func globalProviderDefaults = { world: () => rdfWorldProvider() };
alias GlobalProviderWithDefaults = ProviderWithDefaults!(Callable!((RedlandWorldWithoutFinalize world) => Global(world)),
GlobalProvidersParams,
globalProviderDefaults);
GlobalProviderWithDefaults globalProvider;
static this() {
globalProvider = new GlobalProviderWithDefaults();
}
4 changes: 4 additions & 0 deletions source/xmlboiler/core/execution_context_builders.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

module xmlboiler.core.execution_context_builders;

public import xmlboiler.core.execution_context;

// TODO
2 changes: 2 additions & 0 deletions source/xmlboiler/core/graph/connect.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

module xmlboiler.core.graph.connect;

import xmlboiler.core.graph.relation;

GraphT transitive_closure(GraphT)(GraphT graph) {
Expand Down
109 changes: 109 additions & 0 deletions source/xmlboiler/core/rdf_base/subclass.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import struct_params;
import pure_dependency.providers;
import anansi.adjacencylist;
import rdf.redland.world;
import rdf.redland.node;
import rdf.redland.statement;
import xmlboiler.core.data : Global;
import xmlboiler.core.graph.relation : BinaryRelation;
import xmlboiler.core.graph.connect : Connectivity;
import xmlboiler.core.execution_context_builders;
import xmlboiler.core.data;

class SubclassRelation : Connectivity!Node {
RedlandWorldWithoutFinalize world;
ExecutionContext context;
RDFNode relation;
this(RedlandWorldWithoutFinalize _world,
ExecutionContext _context,
AdjacencyList graph=AdjacencyList(),
RDFNode _relation=Node.fromURIString(world, "http://www.w3.org/2000/01/rdf-schema#subClassOf"))
{
super();
world = _world;
context = _context;
relation = _relation;
add_graph( graph);
}

bool add_graph(ModelWithoutFinalize graph) {
auto result = BinaryRelation();
bool were_errors = false;
foreach (st; graph.find( new Statement( null, relation, null))) {
auto subject = st.subject;
auto object = st.object;
if (object.isResource) {
if (check_types( graph, subject, object))
result.add_edge( subject, object);
} else {
were_errors = true;
immutable msg = context.translations.gettext("Node %s should be an IRI.").format(object);
context.logger.warning( msg);
}
}
add_relation( result);
return !were_errors;
}
bool check_types(ModelWithoutFinalize graph, NodeWithoutFinalize src, NodeWithoutFinalize dst) {
return True;
}
}

class SubclassRelationForType : SubclassRelation!T {
Node node_class;
this(NodeWithoutFinalize _node_class,
RedlandWorldWithoutFinalize _world,
ExecutionContext _context,
AdjacencyList graph=AdjacencyList(),
RDFNode _relation=Node.fromURIString(world, "http://www.w3.org/2000/01/rdf-schema#subClassOf"))
{
node_class = _node_class; // need to set before super()
super(_world, _context, _graph, _relation);
}
def check_types(ModelWithoutFinalize graph, NodeWithoutFinalize src, NodeWithoutFinalize dst) {
src_ok = graph.contains(src, Node.fromURIString(world, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), node_class);
dst_ok = graph.contains(dst, Node.fromURIString(world, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), node_class);
if (src_ok ^ dst_ok) {
immutable msg = context.translations.gettext("Both operands should be of type %s").format(node_class);
context.logger.warning(msg);
}
return src_ok && dst_ok;
}
}

shared basic_subclasses_graph = ThreadSafeCallableSingleton!(
() => globalProvider().load_rdf("core/data/subclasses.ttl"));

Provider!(SubclassRelation, RedlandWorldWithoutFinalize, ExecutionContext, AdjacencyList, Node) subclassRelationProvider;
mixin StructParams!("SubclassRelationParams", RedlandWorldWithoutFinalize, "world",
ExecutionContext, "context",
AdjacencyList, "graph",
Node, "relation");

immutable SubclassRelationProvidersParams.Func subclassRelationProviderDefaults = {
world: () => rdfWorldProvider(),
context: () => null, // FIXME: Contexts.execution_context,
graph: () => basic_subclasses_graph,
};
alias SubclassRelationProviderWithDefaults = ProviderWithDefaults!(Callable!(
(RedlandWorldWithoutFinalize world, ExecutionContext context, AdjacencyList graph, RDFNode t)
=> SubclassRelation(world, context, grap, t)),
SubclassRelationProvidersParams,
globalProviderDefaults);
static this() {
subclassRelationProvider = new SubclassRelationProviderWithDefaults();
}

immutable SubclassRelationForTypeProvidersParams.Func subclassRelationForTypeProviderDefaults = {
world: () => rdfWorldProvider(),
context: () => null, // FIXME: Contexts.execution_context,
graph: () => basic_subclasses_graph,
};
alias SubclassRelationForTypeProviderWithDefaults = ProviderWithDefaults!(Callable!(
(RedlandWorldWithoutFinalize world, ExecutionContext context, AdjacencyList graph, Node t)
=> SubclassRelationForType(world, context, grap, t)),
SubclassRelationForTypeProvidersParams,
globalProviderDefaults);
static this() {
subclassRelationProvider = new SubclassRelationForTypeProviderWithDefaults();
}

0 comments on commit f24d985

Please sign in to comment.