parent
9cd36b4c44
commit
8d2cbfb685
@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Literal
|
||||
* Copyright 2011 by Michael Peter Christen, mc@yacy.net, Frankfurt am Main, Germany
|
||||
* First released 18.12.2011 at http://yacy.net
|
||||
*
|
||||
* $LastChangedDate: 2011-04-14 00:04:23 +0200 (Do, 14 Apr 2011) $
|
||||
* $LastChangedRevision: 7653 $
|
||||
* $LastChangedBy: orbiter $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.yacy.cora.lod;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.yacy.cora.document.MultiProtocolURI;
|
||||
|
||||
/**
|
||||
* A literal is the possible value for a predicate.
|
||||
* A set of literals is the norm of a predicate.
|
||||
* Each literal can have an attached explanation which we express
|
||||
* as a link to the resource that explains the literal.
|
||||
*/
|
||||
public interface Literal {
|
||||
|
||||
/**
|
||||
* the terminal is the actual content of the property and also
|
||||
* the visual representation of the content of a property if the
|
||||
* literal is assigned to that property.
|
||||
* @return a string representing the literal
|
||||
*/
|
||||
public String getTerminal();
|
||||
|
||||
/**
|
||||
* the subject of a literal is a reference to a resource that
|
||||
* explains the literal. If an object has attached properties
|
||||
* from different vocabularies and properties assigned to the
|
||||
* object have actual literal instances assigned, then the set
|
||||
* of subjects of these literals explain the object as a co-notation
|
||||
* to knowledge. Subjects of literals shall therefore be
|
||||
* knowledge authorities for the predicates where the literal is
|
||||
* assigned.
|
||||
* @return an url to a knowledge authority for the literal
|
||||
*/
|
||||
public MultiProtocolURI getSubject();
|
||||
|
||||
/**
|
||||
* if a resource is poorly annotated with metadata an it shall
|
||||
* be automatically annotated, then the terminal of a literal
|
||||
* may be too weak to discover literals in the resource. An additional
|
||||
* discovery pattern may help to reduce the set of literals that can
|
||||
* be discovered automatically. A discovery pattern is then not
|
||||
* a replacement of the terminal itself, it is an additional pattern
|
||||
* that must occur also in the resource where also the terminal of
|
||||
* the literal appears. If the terminal itself is sufficient to discover
|
||||
* the literal, then the discovery pattern may be a catch-all '.*' pattern.
|
||||
* @return the discovery pattern to identify the literal in the resource.
|
||||
*/
|
||||
public Pattern getDiscoveryPattern();
|
||||
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Syntax
|
||||
* Copyright 2011 by Michael Peter Christen, mc@yacy.net, Frankfurt am Main, Germany
|
||||
* First released 17.12.2011 at http://yacy.net
|
||||
*
|
||||
* $LastChangedDate: 2011-04-14 00:04:23 +0200 (Do, 14 Apr 2011) $
|
||||
* $LastChangedRevision: 7653 $
|
||||
* $LastChangedBy: orbiter $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.yacy.cora.lod;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.yacy.cora.lod.vocabulary.CreativeCommons;
|
||||
import net.yacy.cora.lod.vocabulary.DublinCore;
|
||||
import net.yacy.cora.lod.vocabulary.Foaf;
|
||||
import net.yacy.cora.lod.vocabulary.Geo;
|
||||
import net.yacy.cora.lod.vocabulary.HttpHeader;
|
||||
import net.yacy.cora.lod.vocabulary.Rdf;
|
||||
import net.yacy.cora.lod.vocabulary.YaCyMetadata;
|
||||
|
||||
/**
|
||||
* helper class to understand xml tags and vocabularies
|
||||
*/
|
||||
public class Syntax {
|
||||
|
||||
private final static Class<?>[] vocabularies = new Class<?>[]{
|
||||
CreativeCommons.class,
|
||||
DublinCore.class,
|
||||
Foaf.class,
|
||||
Geo.class,
|
||||
HttpHeader.class,
|
||||
Rdf.class,
|
||||
YaCyMetadata.class
|
||||
};
|
||||
|
||||
private final static Map<String, Vocabulary> tagMap = new HashMap<String, Vocabulary>();
|
||||
|
||||
static {
|
||||
Vocabulary voc;
|
||||
for (Class<?> v: vocabularies) {
|
||||
Object[] cs = v.getEnumConstants();
|
||||
for (Object c: cs) {
|
||||
voc = (Vocabulary) c;
|
||||
tagMap.put(voc.getPredicate(), voc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* recognizer for vocabulary tag names
|
||||
* @param tag
|
||||
* @return the vocabulary object for the given tag
|
||||
*/
|
||||
public static Vocabulary getVocabulary(String tag) {
|
||||
return tagMap.get(tag);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(tagMap);
|
||||
}
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
/**
|
||||
* CreativeCommons
|
||||
* Copyright 2011 by Michael Peter Christen, mc@yacy.net, Frankfurt am Main, Germany
|
||||
* First released 17.12.2011 at http://yacy.net
|
||||
*
|
||||
* $LastChangedDate: 2011-04-14 00:04:23 +0200 (Do, 14 Apr 2011) $
|
||||
* $LastChangedRevision: 7653 $
|
||||
* $LastChangedBy: orbiter $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.yacy.cora.lod.vocabulary;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.yacy.cora.document.MultiProtocolURI;
|
||||
import net.yacy.cora.lod.Literal;
|
||||
import net.yacy.cora.lod.Vocabulary;
|
||||
|
||||
/**
|
||||
* a vocabulary for creative commons license declarations. see:
|
||||
* http://creativecommons.org/ns#
|
||||
*/
|
||||
public enum CreativeCommons implements Vocabulary {
|
||||
|
||||
// License Properties
|
||||
permits(new Literal[]{
|
||||
PermitLiteral.Reproduction,
|
||||
PermitLiteral.Distribution,
|
||||
PermitLiteral.DerivativeWorks,
|
||||
PermitLiteral.Sharing}),
|
||||
requires,
|
||||
prohibits,
|
||||
jurisdiction,
|
||||
legalcode,
|
||||
deprecatedOn,
|
||||
|
||||
// Work Properties
|
||||
license,
|
||||
morePermissions,
|
||||
attributionName,
|
||||
attributionURL,
|
||||
useGuidelines;
|
||||
|
||||
|
||||
enum PermitLiteral implements Literal {
|
||||
|
||||
Reproduction("Reproduction", null, ".*"),
|
||||
Distribution("Distribution", null, ".*"),
|
||||
DerivativeWorks("Derivative Works",null, ".*"),
|
||||
Sharing("Sharing", null, ".*");
|
||||
|
||||
String terminal;
|
||||
MultiProtocolURI subject;
|
||||
Pattern discoveryPattern;
|
||||
|
||||
private PermitLiteral(
|
||||
String terminal,
|
||||
String subject,
|
||||
String discoveryPattern) {
|
||||
this.terminal = terminal;
|
||||
try {
|
||||
this.subject = subject == null ? null : new MultiProtocolURI(subject);
|
||||
} catch (MalformedURLException e) {
|
||||
this.subject = null;
|
||||
}
|
||||
this.discoveryPattern = Pattern.compile(discoveryPattern == null ? ".*" : discoveryPattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTerminal() {
|
||||
return this.terminal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiProtocolURI getSubject() {
|
||||
return this.subject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern getDiscoveryPattern() {
|
||||
return this.discoveryPattern;
|
||||
}
|
||||
}
|
||||
|
||||
public final static String IDENTIFIER = "http://dublincore.org/documents/2010/10/11/dces/";
|
||||
public final static String PREFIX = "cc";
|
||||
|
||||
private final String predicate;
|
||||
private final Set<Literal> literals;
|
||||
|
||||
private CreativeCommons() {
|
||||
this.predicate = PREFIX + ":" + this.name();
|
||||
this.literals = null;
|
||||
}
|
||||
|
||||
private CreativeCommons(Literal[] literals) {
|
||||
this.predicate = PREFIX + ":" + this.name();
|
||||
this.literals = new HashSet<Literal>();
|
||||
for (Literal l: literals) this.literals.add(l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return IDENTIFIER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
return PREFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Literal> getLiterals() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPredicate() {
|
||||
return this.predicate;
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Foaf
|
||||
* Copyright 2011 by Michael Peter Christen, mc@yacy.net, Frankfurt am Main, Germany
|
||||
* First released 17.12.2011 at http://yacy.net
|
||||
*
|
||||
* $LastChangedDate: 2011-04-14 00:04:23 +0200 (Do, 14 Apr 2011) $
|
||||
* $LastChangedRevision: 7653 $
|
||||
* $LastChangedBy: orbiter $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.yacy.cora.lod.vocabulary;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import net.yacy.cora.lod.Literal;
|
||||
import net.yacy.cora.lod.Vocabulary;
|
||||
|
||||
/**
|
||||
* The friend of a friend vocabulary. see:
|
||||
* http://xmlns.com/foaf/spec/
|
||||
*/
|
||||
public enum Foaf implements Vocabulary {
|
||||
;
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Literal> getLiterals() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPredicate() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Rdf
|
||||
* Copyright 2011 by Michael Peter Christen, mc@yacy.net, Frankfurt am Main, Germany
|
||||
* First released 17.12.2011 at http://yacy.net
|
||||
*
|
||||
* $LastChangedDate: 2011-04-14 00:04:23 +0200 (Do, 14 Apr 2011) $
|
||||
* $LastChangedRevision: 7653 $
|
||||
* $LastChangedBy: orbiter $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.yacy.cora.lod.vocabulary;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import net.yacy.cora.lod.Literal;
|
||||
import net.yacy.cora.lod.Vocabulary;
|
||||
|
||||
public enum Rdf implements Vocabulary {
|
||||
|
||||
RDF,
|
||||
Description,
|
||||
Bag,
|
||||
Seq,
|
||||
Alt;
|
||||
|
||||
public final static String IDENTIFIER = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
|
||||
public final static String PREFIX = "rdf";
|
||||
|
||||
private final String predicate;
|
||||
|
||||
private Rdf() {
|
||||
this.predicate = PREFIX + ":" + this.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return IDENTIFIER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
return PREFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Literal> getLiterals() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPredicate() {
|
||||
return this.predicate;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue