schemaOrg

A Java implementation of schema.org data structure

License

License

Categories

Categories

Doma Data ORM
GroupId

GroupId

org.kyojo
ArtifactId

ArtifactId

kyojo-schemaorg-m3n4-digest-doma
Last Version

Last Version

0.7.0
Release Date

Release Date

Type

Type

jar
Description

Description

schemaOrg
A Java implementation of schema.org data structure
Project URL

Project URL

https://github.com/nagaikenshin/schemaOrg
Source Code Management

Source Code Management

https://github.com/nagaikenshin/schemaOrg/tree/master

Download kyojo-schemaorg-m3n4-digest-doma

How to add to project

<!-- https://jarcasting.com/artifacts/org.kyojo/kyojo-schemaorg-m3n4-digest-doma/ -->
<dependency>
    <groupId>org.kyojo</groupId>
    <artifactId>kyojo-schemaorg-m3n4-digest-doma</artifactId>
    <version>0.7.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.kyojo/kyojo-schemaorg-m3n4-digest-doma/
implementation 'org.kyojo:kyojo-schemaorg-m3n4-digest-doma:0.7.0'
// https://jarcasting.com/artifacts/org.kyojo/kyojo-schemaorg-m3n4-digest-doma/
implementation ("org.kyojo:kyojo-schemaorg-m3n4-digest-doma:0.7.0")
'org.kyojo:kyojo-schemaorg-m3n4-digest-doma:jar:0.7.0'
<dependency org="org.kyojo" name="kyojo-schemaorg-m3n4-digest-doma" rev="0.7.0">
  <artifact name="kyojo-schemaorg-m3n4-digest-doma" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.kyojo', module='kyojo-schemaorg-m3n4-digest-doma', version='0.7.0')
)
libraryDependencies += "org.kyojo" % "kyojo-schemaorg-m3n4-digest-doma" % "0.7.0"
[org.kyojo/kyojo-schemaorg-m3n4-digest-doma "0.7.0"]

Dependencies

runtime (2)

Group / Artifact Type Version
commons-logging : commons-logging jar 1.2
org.seasar.doma : doma jar 2.19.2

Project Modules

There are no modules declared in this project.

schemaOrg

Overview

A Java implementation of schema.org data structure.

Class and Property types mapping

(schema.org's) class types mapped like

http://schema.org/Person
org.kyojo.schemaorg.m3n4.core.Clazz$Person

Property types mapped like

http://schema.org/author
org.kyojo.schemaorg.m3n4.core.Container$Author

These are interfaces and have each entity classes like

org.kyojo.schemaorg.m3n4.core.impl.PERSON
org.kyojo.schemaorg.m3n4.core.impl.AUTHOR

Class and Property types field possession

(schema.org's) class types has fields of (schema.org's) property types in the singular object.

org.kyojo.schemaorg.m3n4.core.Clazz$CreativeWork
    public Container.Author getAuthor();
    public void setAuthor(Container.Author author);

Property types has fields of class types in the List object.

org.kyojo.schemaorg.m3n4.core.Container$Author
    public Clazz.Person getPerson();
    public void setPerson(Clazz.Person person);
    public List<Clazz.Person> getPersonList();
    public void setPersonList(List<Clazz.Person> personList);
    public boolean hasPerson();

Just like above, property types are accessed with getter/setter methods, and class types with 5 kinds of methods.

Main constructors

General class type's entity classes has at least 2 constructors, no arguments and one String. If one String given, it is interpreted as a name property given.

    public PERSON() {
    }

    public PERSON(String string) {
        setName(new NAME(new TEXT(string)));
    }

Dedicated JSON builder

org.kyojo.schemaorg.SimpleJsonBuilder is the JSON builder for JSONizing schemeOrg objects. It is added some functions internally no other general JSON builders provide, but enough available as a simple JSON builder for any purpose.

CreativeWork creativeWork = new CREATIVE_WORK();
Author author = new AUTHOR(new PERSON("誰か"));
creativeWork.setAuthor(author);
System.out.println(SimpleJsonBuilder.toJson(creativeWork));
System.out.println(SimpleJsonBuilder.toJsonLd(creativeWork, CreativeWork.class));

Results:

{"author":{"person":{"name":{"text":"誰か"}}}}
{"@context":"http:\/\/schema.org","@type":"CreativeWork","author":{"@context":"http:\/\/schema.org","@type":"Person","name":"誰か"}}

Sample source

GSON assumed for deserialization

The deserialization JSONized schemaOrg objects is GSON use assumed. The correspondence list of interfaces and deserializers is written in org.kyojo.schemaorg.m3n4.gson.GsonTypeAdapters.properties. Load and register by GsonBuilder calling registerTypeAdapter() method.

JSON structure analyzing utility class

org.kyojo.schemaorg.SimpleJsonWalker is the utility class for analyzing JSON structure. It realize the formatting JSON and the conversion JSON-LD to JSON. If this JSON-LD is the data structure of schema.org, the converted JSON is deserializable to a schemaOrg object.

JSON-LD:

{
    "@context": "http://schema.org",
    "@type": "NewsArticle",
    "mainEntityOfPage": {
        "@type": "WebPage",
        "@id": "https://google.com/article"
    },
    "headline": "Article headline",
    "image": [
        "https://example.com/photos/1x1/photo.jpg",
        "https://example.com/photos/4x3/photo.jpg",
        "https://example.com/photos/16x9/photo.jpg"
    ],
    "datePublished": "2015-02-05",
    "dateModified": "2015-02-05T09:20:00+08:00",
    "author": {
        "@type": "Person",
        "name": "John Doe"
    },
    "publisher": {
        "@type": "Organization",
        "name": "Google",
        "logo": {
            "@type": "ImageObject",
            "url": "https://google.com/logo.jpg"
        }
    },
    "description": "A most wonderful article"
}
Map<String, JsonLdThingStringGiven> thingStrModeMap = new HashMap<>();
thingStrModeMap.put("url", JsonLdThingStringGiven.AS_URL);
thingStrModeMap.put("image", JsonLdThingStringGiven.AS_URL);
thingStrModeMap.put("item", JsonLdThingStringGiven.AS_THING_IDENTIFIER_URL);
Map<String, String> jsonLdRootMap = new HashMap<>();
String json1 = SimpleJsonWalker.jsonLdToJson(jsonLd, jsonLdRootMap,
        thingStrModeMap, JsonLdAtIdStringGiven.AS_AUTO);
String json2 = SimpleJsonWalker.formatJson(json1, "\t");
System.out.println(json2);

Results:

{
    "datePublished" : "2015-02-05",
    "image" : {
        "url" : [
            "https://example.com/photos/1x1/photo.jpg",
            "https://example.com/photos/4x3/photo.jpg",
            "https://example.com/photos/16x9/photo.jpg"
        ]
    },
    "author" : {
        "person" : {
            "name" : "John Doe"
        }
    },
    "publisher" : {
        "organization" : {
            "name" : "Google",
            "logo" : {
                "imageObject" : {
                    "url" : {
                        "url" : "https://google.com/logo.jpg"
                    }
                }
            }
        }
    },
    "description" : "A most wonderful article",
    "dateModified" : "2015-02-05T09:20:00+08:00",
    "mainEntityOfPage" : {
        "webPage" : {
            "identifier" : {
                "url" : "https:\/\/google.com\/article"
            }
        }
    },
    "headline" : "Article headline"
}

Sample source

Web framework integration

kyojoLib is the web framework natively supports the data structure of schema.org.

Short examples found here.

Included Projects

  • schemaOrgWork - The generator of the following 4 projects classes source codes.
  • schemaOrgImpl - The implementation classes. (ordinary use)
  • schemaOrgGson - GSON deserializers for schemaOrgImpl.
  • schemaOrgDoma - schemaOrgImpl added Doma domain class use features.
  • schemaOrgDomaConv - Converters for schemaOrgDoma.

Maven Repository

There are two level of detail implementations full and digest. The full implementation is not suitable for realtime processing. The digest implementation is also provided, extracted important classes for general purpose.

Versions

Version
0.7.0