https://gitlab.inria.fr/line/aide-group/macrovsa
Tip revision: 31a87d848f8ab28a06ccf77d0b359fc966974138 authored by vthierry on 15 December 2025, 21:31:50 UTC
sync from makefile
sync from makefile
Tip revision: 31a87d8
pizza_experiments.C
#include "macrovsa.hpp"
#include "time.hpp"
using namespace macrovsa;
/* Experiment corresponding to the (Viéville & Mercier 2024) draft
* @param {bool} [with_RDFSS = true] Defines if we add extra RDFSs supplementary inferences.
* @param {double} [tau_eat = 1] Defines if exact (tau_eat = 1) or approximate (tau_eat = 0.5) inference on eating.
* @param {String} [trace = "ado"] Level of trace as defined Rules.hpp.
*/
void pizza_experiment(bool with_RDFSS = true, double tau_eat = 1, String trace = "ado")
{
printf("pizza_experiment(bool with_RDFSS = %d, double tau_eat = %f, String trace = '%s'\n", with_RDFSS, tau_eat, trace.c_str());
class SomeRules: public Rules {
public:
SomeRules(String trace, bool with_RDFSS) : Rules(0, trace) {
//
// RDFS segment entailment rules
//
// ClassInheritance
Rule_2(rdfs9,
// getTau()
return algo::conj(algo::sim(predicate_1, "rdf:type"), algo::sim(object_1, subject_2), algo::sim(predicate_2, "rdfs:subClassOf"));
,
// setOutput()
output.add(*subject_1, tau, "rdf:type", *object_2);
);
// ClassTransitivity
Rule_2(rdfs11,
// getTau()
return algo::conj(algo::sim(predicate_1, "rdfs:subClassOf"), algo::sim(object_1, subject_2), algo::sim(predicate_2, "rdfs:subClassOf"));
,
// setOutput()
output.add(*subject_1, tau, "rdfs:subClassOf", *object_2);
);
// DomainInference
Rule_2(rdfs2,
// getTau()
return algo::conj(algo::sim(predicate_1, subject_2), algo::sim(predicate_2, "rdfs:domain"));
,
// setOutput()
output.add(*subject_1, tau, "rdf:type", *object_2);
);
// RangeInference
Rule_2(rdfs3,
// getTau()
return algo::conj(algo::sim(predicate_1, subject_2), algo::sim(predicate_2, "rdfs:range"));
,
// setOutput()
output.add(*object_1, tau, "rdf:type", *object_2);
);
// PropertyInference
Rule_2(rdfs7,
// getTau()
return algo::conj(algo::sim(predicate_1, subject_2), algo::sim(predicate_2, "rdfs:subPropertyOf"));
,
// setOutput()
output.add(*subject_1, tau, *object_2, *object_1);
);
//
// Additional entailment rules to infer node types
// - Note: this is mainly used to examplify and test Rule_1 and Rule_3 macro and multiple outputs
//
if(with_RDFSS) {
// PropertyTypeInference
Rule_1(rdf1,
// getTau()
return 1;
,
// setOutput()
output.add(*predicate_1, "rdf:type", "rdfs:Property");
);
// ClassTypeInference
Rule_1(rdfss1,
// getTau()
return algo::sim(predicate_1, "rdf:type");
,
// setOutput()
output.add(*object_1, tau, "rdf:type", "rdfs:Class");
);
Rule_1(rdfss2,
// getTau()
return algo::sim(predicate_1, "rdfs:subClassOf");
,
// setOutput()
output.add(*subject_1, tau, "rdf:type", "rdfs:Class");
output.add(*object_1, tau, "rdf:type", "rdfs:Class");
);
Rule_1(rdfss3,
// getTau()
return algo::sim(predicate_1, "rdfs:subPropertyOf");
,
// setOutput()
output.add(*subject_1, tau, "rdf:type", "rdfs:Property");
output.add(*object_1, tau, "rdf:type", "rdfs:Property");
);
// PropertyClassInheritance
Rule_3(rdfss9,
// getTau()
return algo::conj(algo::sim(predicate_1, "rdf:type"), algo::sim(object_1, subject_2), algo::sim(predicate_2, subject_3), algo::sim(predicate_3, "rdf:type"), algo::sim(object_3, "rdfs:Property"));
,
// setOutput()
output.add(*subject_1, tau, *predicate_2, *object_2);
);
}
}
}
someRules(trace, with_RDFSS);
// Defines incoming facts
RelationalMap incoming("Luigi pizza incomimg facts");
incoming.add("Luigi", tau_eat, "eats", "thisPizza");
incoming.add("eats", "rdfs:domain", "Person");
incoming.add("eats", "rdfs:range", "Food");
incoming.add("thisPizza", "rdf:type", "MagheritaPizza");
incoming.add("thisPizza", "hasTopping", "thisMozzarella");
incoming.add("MagheritaPizza", "rdfs:subClassOf", "Pizza");
incoming.add("Pizza", "rdfs:subClassOf", "Food");
incoming.add("hasTopping", "rdfs:subPropertyOf", "hasIngredient");
incoming.add("MagheritaPizza", "hasTopping", "Tomato");
// Runs inference
RelationalMap infered("Luigi pizza infered facts");
aidesys::now(false, false);
someRules.apply(infered, incoming);
printf("Calculus duration in msec : %.3f\n", aidesys::now(false, true));
printf("%s\n", infered.asString().c_str());
}
int main()
{
pizza_experiment(false, 1, "ado");
pizza_experiment(false, 1, "");
pizza_experiment(false, 0.5, "");
pizza_experiment(true, 1, "");
return 0;
}
