Skip to content

Instantly share code, notes, and snippets.

@justin2004
Last active January 2, 2023 15:55
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justin2004/f9d07adf4e7c2c422be3e0ba92f278d2 to your computer and use it in GitHub Desktop.
Save justin2004/f9d07adf4e7c2c422be3e0ba92f278d2 to your computer and use it in GitHub Desktop.
RDFS Reasoner Challenge (Tbox with 3M triples)

RDFS Reasoner Challenge (~3M Tbox triples, 1 Abox triple)

Goal

The goal is simple: infer class membership (using rdfs:subClassOf and rdf:type predicates). Don't do it with a property path or something. You must let the reasoner do it.

Attempts

I've tried to do this with a few reasoners. All unsuccessful.

  • Apache Jena wasn't able to do it with 12GB of RAM.
  • Stardog wasn't able to do it with 12GB of RAM.
  • REQUIEM wasn't able to do it with 12GB of RAM.

Data

In this zip file you'll find tbox.ttl and abox.ttl.

Query

This is the query that should return 79 results:

PREFIX  wd:   <http://www.wikidata.org/entity/>
PREFIX  ex:   <http://example.com/>
SELECT  *
WHERE
  { ex:condition0 a ?type
  }

Without reasoning it yields 1 result:

type
http://www\.wikidata\.org/entity/Q32552

But with RDFS reasoning enabled there should be 79 results.

e.g.

PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX  ex:   <http://example.com/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX  wd:   <http://www.wikidata.org/entity/>
SELECT  *
WHERE
  { ex:condition0 rdf:type/(rdfs:subClassOf)* ?type }

Yields:

type
http://www\.wikidata\.org/entity/Q32552
http://www\.wikidata\.org/entity/Q12397808
http://www\.wikidata\.org/entity/Q32540
http://www\.wikidata\.org/entity/Q12192
http://www\.wikidata\.org/entity/Q3392853
http://www\.wikidata\.org/entity/Q18553224
http://www\.wikidata\.org/entity/Q3286546
http://www\.wikidata\.org/entity/Q12136
http://www\.wikidata\.org/entity/Q2057971
http://www\.wikidata\.org/entity/Q7189713
http://www\.wikidata\.org/entity/Q3505845
http://www\.wikidata\.org/entity/Q937228
http://www\.wikidata\.org/entity/Q35120
http://www\.wikidata\.org/entity/Q483247
http://www\.wikidata\.org/entity/Q1190554
http://www\.wikidata\.org/entity/Q26907166
http://www\.wikidata\.org/entity/Q58415929
http://www\.wikidata\.org/entity/Q16722960
http://www\.wikidata\.org/entity/Q1149305
http://www\.wikidata\.org/entity/Q55919789
http://www\.wikidata\.org/entity/Q1207505
http://www\.wikidata\.org/entity/Q18603648
http://www\.wikidata\.org/entity/Q813912
http://www\.wikidata\.org/entity/Q21170479
http://www\.wikidata\.org/entity/Q18557436
http://www\.wikidata\.org/entity/Q3631290
http://www\.wikidata\.org/entity/Q754447
http://www\.wikidata\.org/entity/Q18123741
http://www\.wikidata\.org/entity/Q42417296
http://www\.wikidata\.org/entity/Q25383952
http://www\.wikidata\.org/entity/Q1284347
http://www\.wikidata\.org/entity/Q42183538
http://www\.wikidata\.org/entity/Q1441305
http://www\.wikidata\.org/entity/Q28807560
http://www\.wikidata\.org/entity/Q639907
http://www\.wikidata\.org/entity/Q193181
http://www\.wikidata\.org/entity/Q160402
http://www\.wikidata\.org/entity/Q781413
http://www\.wikidata\.org/entity/Q2996394
http://www\.wikidata\.org/entity/Q3249551
http://www\.wikidata\.org/entity/Q1150070
http://www\.wikidata\.org/entity/Q20937557
http://www\.wikidata\.org/entity/Q16887380
http://www\.wikidata\.org/entity/Q28813620
http://www\.wikidata\.org/entity/Q99527517
http://www\.wikidata\.org/entity/Q64732777
http://www\.wikidata\.org/entity/Q13878858
http://www\.wikidata\.org/entity/Q14912053
http://www\.wikidata\.org/entity/Q22299483
http://www\.wikidata\.org/entity/Q22299433
http://www\.wikidata\.org/entity/Q855395
http://www\.wikidata\.org/entity/Q29182544
http://www\.wikidata\.org/entity/Q4026292
http://www\.wikidata\.org/entity/Q169872
http://www\.wikidata\.org/entity/Q101991
http://www\.wikidata\.org/entity/Q31836626
http://www\.wikidata\.org/entity/Q505142
http://www\.wikidata\.org/entity/Q18558143
http://www\.wikidata\.org/entity/Q1963588
http://www\.wikidata\.org/entity/Q42982
http://www\.wikidata\.org/entity/Q14905917
http://www\.wikidata\.org/entity/Q14907126
http://www\.wikidata\.org/entity/Q22271820
http://www\.wikidata\.org/entity/Q14907559
http://www\.wikidata\.org/entity/Q22270763
http://www\.wikidata\.org/entity/Q14916317
http://www\.wikidata\.org/entity/Q14904580
http://www\.wikidata\.org/entity/Q14887714
http://www\.wikidata\.org/entity/Q1612119
http://www\.wikidata\.org/entity/Q14859560
http://www\.wikidata\.org/entity/Q5958765
http://www\.wikidata\.org/entity/Q3843811
http://www\.wikidata\.org/entity/Q929833
http://www\.wikidata\.org/entity/Q14905642
http://www\.wikidata\.org/entity/Q14874298
http://www\.wikidata\.org/entity/Q14819849
http://www\.wikidata\.org/entity/Q14820936
http://www\.wikidata\.org/entity/Q14819911
http://www\.wikidata\.org/entity/Q14907247
@mdesalvo
Copy link

mdesalvo commented Dec 22, 2022

Hi @justin2004,
I followed the goal proposal: we have an API for finding the classes of a given individual in an ontology. Internally it subsumes rdfs:subClassOf taxonomy starting from known rdf:type classes of the individual. The only configuration I did was to disable awareness of owl:equivalentClass (which we support by default) because not stated by the goal.

Strictly speaking in terms of reasoner we don't have a monolithic engine which reads n3 rules and produces answers: we are a library, so we rather expose high-level usable APIs to applications for dealing with ontologies. I built a simple consolle application like this:

using RDFSharp.Model;
using RDFSharp.Semantics;
using System.Diagnostics;

Console.Write("Loading graph...");
Stopwatch sw = Stopwatch.StartNew();
RDFGraph abox = await RDFGraph.FromFileAsync(RDFModelEnums.RDFFormats.Turtle, Environment.CurrentDirectory + "\\abox.ttl");
RDFGraph tbox = await RDFGraph.FromFileAsync(RDFModelEnums.RDFFormats.Turtle, Environment.CurrentDirectory + "\\tbox.ttl");
foreach (RDFTriple aboxTriple in abox)
    tbox.AddTriple(aboxTriple);
sw.Stop();
Console.WriteLine($"DONE! {tbox.TriplesCount} triples in {sw.Elapsed}");

Console.Write("Loading ontology...");
sw.Restart();
OWLOntology ontology = await OWLOntology.FromRDFGraphAsync(tbox, 
    new OWLOntologyLoaderOptions() { EnableTaxonomyProtection=false, EnableAutomaticEntityDeclaration=true });
sw.Stop();
Console.WriteLine($"DONE! {ontology.Model.ClassModel.ClassesCount} classes, " +
    $"{ontology.Model.PropertyModel.PropertiesCount} properties, " +
    $"{ontology.Data.IndividualsCount} individuals in {sw.Elapsed}");

Console.Write("Loading data lens...");
sw.Restart();
OWLOntologyDataLens datalens = new OWLOntologyDataLens(new RDFResource("http://example.com/condition0"), ontology);
List<RDFResource> classTypes = await datalens.ClassTypesAsync(false);
sw.Stop();
Console.WriteLine($"DONE! {classTypes.Count} classes in {sw.Elapsed}");

Regards,
Marco

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment