/** * @param <T> type of the class * @param clazz of the individual use to general the iri of the individual * @return a random iri that fit the name of an individiual * @since 2.5.1 */ public static <T> IRI rand(final Class<T> clazz) { return IRI.create(base(clazz) + OWLHelper._entitySeparator + randId(clazz.getSimpleName())); }
/** * @param rand is a String generated with the the randStr() method. * @return an Instant as parsed from a String generated with the randStr() method. * @since 2.6.0 */ public static Instant instantFromRandStr(final String rand) { return instantFromShortTime(rand.substring(rand.indexOf(OWLHelper._innerSeparator) + 1, rand.lastIndexOf(OWLHelper._innerSeparator))); }
/** * @param begin will be placed at the start of the result. * @return a random String with the given String placed at the start and two inner separator around the random part. * @since 2.5.1 */ public static String randId(final String begin) { return begin + OWLHelper._innerSeparator + randStr() + OWLHelper._innerSeparator; }
/** * To avoid problem on declaration of the individual, this method get template of individual : class + namespace + name. And add some random around the * name. * * @param owlClazz that must be bind to the individual * @param namespace of the individual to create. * @param name of the individual to create. * @return A new named individual. * @Deprecated 2.6.1 This method should take a fully qualified label that depend of the context. No more next int usage. */ @Deprecated default public OWLNamedIndividual declareIndividual(final OWLClass owlClazz, final String namespace, final String name) { return declareIndividual(owlClazz, IRI.create((IRIUtils.isIRI(name)) ? name : namespace + IRIUtils.randId(name))); }
case "Double": case "String": dataMethods.add(DataProperty(IRIUtils.core(iface, method))); break; default: objectMethods.add(ObjectProperty(IRIUtils.core(iface, method))); for (final Class<?> clazz : iface.getInterfaces()) classes.add(Class(IRIUtils.clazz(clazz))); result.addAll(schema(clazz)); result.add(OWL.subClassOf(Class(IRIUtils.clazz(iface)), and(objectMethods, dataMethods, classes))); return result;
public static <T> IRI ontology(final Class<T> clazz, final String purpose, final String entity) { return IRI.create(base(clazz) + OWLHelper._webSeparator + purpose + OWLHelper._entitySeparator + entity); } }
/** * We remove an huge part of the time the flow before the application first start. The aim is just to get shorter ids that will stayed ordered among runs. * * @return a short string that describe a point in time. * @since 2.5.1 */ public static String shortTime() { return shortTime(System.currentTimeMillis()); }
public static <T> IRI method(final Class<T> clazz, final Method m) { return IRI.create(core(clazz, m)); }
/** * @param clazz is a java class * @param individual that will be map to an owl class generated from the java class. * @return the owl class of the individual * @since 2.5.1 */ default public OWLClass declareClassOfIndividual(final Class<?> clazz, final OWLNamedIndividual individual) { final OWLClass owlClazz = toClass(IRIUtils.clazz(clazz)); addClass(individual, owlClazz); return owlClazz; }
/** * Compute the types of an individual. Use this function only if you mix Named and Anonymous individuals. * * @param ind the individual named _or_ anonymous * @return the classes of the individual. * @since 2.5.1 */ default public NodeSet<OWLClass> getTypes(final OWLIndividual ind) { if (ind instanceof OWLAnonymousIndividual) { // We create a temporary named Individual to allow the reasoner to work. final OWLNamedIndividual individual = getFactory().getOWLNamedIndividual(IRI.create(_protocol + OWLHelper.class.getPackage().getName() + _webSeparator + OWLHelper.class.getSimpleName() + _entitySeparator + IRIUtils.randId(OWLHelper.class.getSimpleName()))); final Stream<OWLAxiom> axioms = Stream.of( // getFactory().getOWLDeclarationAxiom(individual), // getFactory().getOWLSameIndividualAxiom(individual, ind) // The temporary named is the same as the anonymous one. ); getManager().addAxioms(getOntology(), axioms); final NodeSet<OWLClass> result = getReasoner().getTypes(individual, false); getManager().removeAxioms(getOntology(), axioms); return result; } else return getReasoner().getTypes((OWLNamedIndividual) ind, false); }
/** * To avoid problem on declaration of the individual, this method get template of individual : class + namespace + name. And add some random around the * name. * * @param owlClazz that must be bind to the individual * @param namespace of the individual to create. * @param name of the individual to create. * @return A new named individual. * @Deprecated 2.6.1 This method should take a fully qualified label that depend of the context. No more next int usage. */ @Deprecated default public OWLNamedIndividual declareIndividual(final OWLClass owlClazz, final String namespace, final String name) { return declareIndividual(owlClazz, IRI.create((IRIUtils.isIRI(name)) ? name : namespace + IRIUtils.randId(name))); }
case "Double": case "String": dataMethods.add(DataProperty(IRIUtils.core(iface, method))); break; default: objectMethods.add(ObjectProperty(IRIUtils.core(iface, method))); for (final Class<?> clazz : iface.getInterfaces()) classes.add(Class(IRIUtils.clazz(clazz))); result.addAll(schema(clazz)); result.add(OWL.subClassOf(Class(IRIUtils.clazz(iface)), and(objectMethods, dataMethods, classes))); return result;
/** * Work for property and individual * * @param clazz of the entity. The entity msut have a clazz, at least its class of creation. * @param entity the name of the object/individual. * @param <T> the type of the clazz * @return an IRI that is standard to the clazz and entity */ public static <T> IRI name(final Class<T> clazz, final String entity) { return IRI.create(base(clazz) + OWLHelper._entitySeparator + entity); }
/** * We remove an huge part of the time the flow before the application first start. The aim is just to get shorter ids that will stayed ordered among runs. * * @return a short string that describe a point in time. * @since 2.5.1 */ public static String shortTime() { return shortTime(System.currentTimeMillis()); }
public static <T> IRI clazz(final Class<T> clazz) { return IRI.create(core(clazz)); }
/** * @param clazz is a java class * @param individual that will be map to an owl class generated from the java class. * @return the owl class of the individual * @since 2.5.1 */ default public OWLClass declareClassOfIndividual(final Class<?> clazz, final OWLNamedIndividual individual) { final OWLClass owlClazz = toClass(IRIUtils.clazz(clazz)); addClass(individual, owlClazz); return owlClazz; }
/** * Compute the types of an individual. Use this function only if you mix Named and Anonymous individuals. * * @param ind the individual named _or_ anonymous * @return the classes of the individual. * @since 2.5.1 */ default public NodeSet<OWLClass> getTypes(final OWLIndividual ind) { if (ind instanceof OWLAnonymousIndividual) { // We create a temporary named Individual to allow the reasoner to work. final OWLNamedIndividual individual = getFactory().getOWLNamedIndividual(IRI.create(_protocol + OWLHelper.class.getPackage().getName() + _webSeparator + OWLHelper.class.getSimpleName() + _entitySeparator + IRIUtils.randId(OWLHelper.class.getSimpleName()))); final Stream<OWLAxiom> axioms = Stream.of( // getFactory().getOWLDeclarationAxiom(individual), // getFactory().getOWLSameIndividualAxiom(individual, ind) // The temporary named is the same as the anonymous one. ); getManager().addAxioms(getOntology(), axioms); final NodeSet<OWLClass> result = getReasoner().getTypes(individual, false); getManager().removeAxioms(getOntology(), axioms); return result; } else return getReasoner().getTypes((OWLNamedIndividual) ind, false); }
/** * @param <T> type of the class * @param clazz of the individual use to general the iri of the individual * @return a random iri that fit the name of an individiual * @since 2.5.1 */ public static <T> IRI rand(final Class<T> clazz) { return IRI.create(base(clazz) + OWLHelper._entitySeparator + randId(clazz.getSimpleName())); }
/** * To avoid problem on declaration of the individual, this method get template of individual : class + namespace + name. And add some random around the * name. * * @param owlClazz that must be bind to the individual * @param namespace of the individual to create. * @param name of the individual to create. * @return A new named individual. * @Deprecated 2.6.1 This method should take a fully qualified label that depend of the context. No more next int usage. */ @Deprecated default public OWLNamedIndividual declareIndividual(final OWLClass owlClazz, final String namespace, final String name) { return declareIndividual(owlClazz, IRI.create((IRIUtils.isIRI(name)) ? name : namespace + IRIUtils.randId(name))); }
case "Double": case "String": dataMethods.add(DataProperty(IRIUtils.core(iface, method))); break; default: objectMethods.add(ObjectProperty(IRIUtils.core(iface, method))); for (final Class<?> clazz : iface.getInterfaces()) classes.add(Class(IRIUtils.clazz(clazz))); result.addAll(schema(clazz)); result.add(OWL.subClassOf(Class(IRIUtils.clazz(iface)), and(objectMethods, dataMethods, classes))); return result;