java.lang.Object
de.uni_mannheim.informatik.dws.melt.matching_jena_matchers.external.SemanticWordRelationDictionary
de.uni_mannheim.informatik.dws.melt.matching_jena_matchers.external.dbpedia.DBpediaKnowledgeSource
All Implemented Interfaces:
ExternalResource, ExternalResourceWithHypernymCapability, ExternalResourceWithSynonymCapability, HypernymCapability, SynonymCapability

public class DBpediaKnowledgeSource extends SemanticWordRelationDictionary
DBpedia knowledge source. Works with the online endpoint and TDB 1.
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
      Logger for this class.
    • ENDPOINT_URL

      private static final String ENDPOINT_URL
      The public SPARQL endpoint.
      See Also:
    • name

      private String name
    • linker

      private DBpediaLinker linker
    • synonymyBuffer

      ConcurrentMap<String,Set<String>> synonymyBuffer
      Buffer for repeated synonymy requests.
    • hypernymyBuffer

      ConcurrentMap<String,Set<String>> hypernymyBuffer
      Buffer for repeated hypernymy requests.
    • excludedHypernyms

      private Set<String> excludedHypernyms
      DBpedia annotates quite a lot of hypernyms. Some of them may be misleading for some analyses such as "http://www.w3.org/2002/07/owl#Thing".
    • persistenceService

      private PersistenceService persistenceService
      Service responsible for disk buffers.
    • isDiskBufferEnabled

      private boolean isDiskBufferEnabled
      If the disk-buffer is disabled, no buffers are read/written from/to the disk. Default: true.
    • isUseTdb

      private boolean isUseTdb
      True if a tdb source shall be used rather than an on-line SPARQL endpoint.
    • tdbDataset

      private org.apache.jena.query.Dataset tdbDataset
      The TDB dataset into which the DBpedia data set was loaded.
    • tdbModel

      private org.apache.jena.rdf.model.Model tdbModel
      TDB model
  • Constructor Details

    • DBpediaKnowledgeSource

      public DBpediaKnowledgeSource()
      Default constructor. SPARQL endpoint will be queried. Disk buffer is enabled by default.
    • DBpediaKnowledgeSource

      public DBpediaKnowledgeSource(boolean isDiskBufferEnabled)
      Constructor for SPARQL access.
      Parameters:
      isDiskBufferEnabled - True if a disk buffer shall be enabled by default.
    • DBpediaKnowledgeSource

      public DBpediaKnowledgeSource(String tdbDirectoryPath)
      Constructor for DBpedia TDB access.
      Parameters:
      tdbDirectoryPath - The path to the TDB directory.
    • DBpediaKnowledgeSource

      public DBpediaKnowledgeSource(String tdbDirectoryPath, boolean isDiskBufferEnabled)
      Constructor for DBpedia TDB access.
      Parameters:
      tdbDirectoryPath - The path to the TDB directory.
      isDiskBufferEnabled - True if the disk buffer shall be enabled.
  • Method Details

    • getEndpointUrl

      public static String getEndpointUrl()
    • initializeMembers

      private void initializeMembers()
      Initializations that have to be performed.
    • initializeHypernymExclusion

      private void initializeHypernymExclusion()
    • initializeLinker

      private void initializeLinker()
      Helper method to initialize the linker.
    • initializeBuffers

      private void initializeBuffers()
      Initialize buffers (either on-disk or memory).
    • isInDictionary

      public boolean isInDictionary(String word)
    • isHypernymous

      public boolean isHypernymous(String linkedConcept_1, String linkedConcept_2)
      Checks for hypernymous words in a loose-form fashion: One concept needs to be a hypernym of the other concept where the order of concepts is irrelevant, i.e., the method returns (hypernymous(w1, w2) || hypernymous(w2, w1). The assumed language is English. CHECKS ONLY FOR LEVEL 1 HYPERNYMY - NO REASONING IS PERFORMED.
      Specified by:
      isHypernymous in interface HypernymCapability
      Overrides:
      isHypernymous in class SemanticWordRelationDictionary
      Parameters:
      linkedConcept_1 - linked word 1
      linkedConcept_2 - linked word 2
      Returns:
      True if the given words are hypernymous, else false.
    • getSynonymsLexical

      @NotNull public @NotNull Set<String> getSynonymsLexical(String linkedConcept)
      Description copied from class: SemanticWordRelationDictionary
      Retrieves a list of synonyms independently of the word sense. The assumed language is English.
      Specified by:
      getSynonymsLexical in interface SynonymCapability
      Specified by:
      getSynonymsLexical in class SemanticWordRelationDictionary
      Parameters:
      linkedConcept - The linked concept for which synonyms shall be retrieved.
      Returns:
      A set of synonyms in word form (not links).
    • isStrongFormSynonymous

      public boolean isStrongFormSynonymous(String link1, String link2)
      Checks for synonymy by determining whether link1 is contained in the set of synonymous words of link2 or vice versa.
      Specified by:
      isStrongFormSynonymous in interface SynonymCapability
      Overrides:
      isStrongFormSynonymous in class SemanticWordRelationDictionary
      Parameters:
      link1 - Word 1
      link2 - Word 2
      Returns:
      True if the given words are synonymous, else false.
    • getSynonymsLexicalQuery

      String getSynonymsLexicalQuery(String link)
      Builds a String query to obtain synonyms. The synonyms are represented by normal words/labels (not URIs).
      Parameters:
      link - The link for which synonymous words shall be obtained.
      Returns:
      A SPARQL query as String.
    • getSubjectPredicateQueryLineForLabels

      static StringBuilder getSubjectPredicateQueryLineForLabels(String subject, String predicate)
      Helper method to build a query.
      Parameters:
      subject - The subject
      predicate - The predicate.
      Returns:
      A string builder.
    • getHypernyms

      @NotNull public @NotNull Set<String> getHypernyms(String linkedConcept)
      Description copied from class: SemanticWordRelationDictionary
      Retrieves a set of hypernyms independently of the word sense. The assumed language is English.
      Specified by:
      getHypernyms in class SemanticWordRelationDictionary
      Parameters:
      linkedConcept - The linked concept for which hypernyms shall be retrieved.
      Returns:
      A set of linked concepts.
    • getHypernymsQuery

      private String getHypernymsQuery(String linkedConcept)
      Construct a query for hypernyms.
      Parameters:
      linkedConcept - The concept for which hypernyms shall be retrieved.
      Returns:
      SPARQL query as String.
    • getSubjectPredicateQueryLineForConcepts

      static StringBuilder getSubjectPredicateQueryLineForConcepts(String subject, String predicate)
      Helper method to build a query.
      Parameters:
      subject - The subject
      predicate - The predicate.
      Returns:
      A string builder.
    • commitAll

      private void commitAll()
      Commit data changes if active.
    • close

      public void close()
      Description copied from class: SemanticWordRelationDictionary
      Closing open resources.
      Specified by:
      close in class SemanticWordRelationDictionary
    • getLinker

      public LabelToConceptLinker getLinker()
      Description copied from interface: ExternalResource
      Returns the linker instance for this particular resource.
      Specified by:
      getLinker in interface ExternalResource
      Specified by:
      getLinker in class SemanticWordRelationDictionary
      Returns:
      The specific linker used to link words to concepts.
    • isUseTdb

      public boolean isUseTdb()
    • getTdbDataset

      public org.apache.jena.query.Dataset getTdbDataset()
    • getName

      public String getName()
      Description copied from interface: ExternalResource
      Obtain the name of the resource.
      Specified by:
      getName in interface ExternalResource
      Specified by:
      getName in class SemanticWordRelationDictionary
      Returns:
      Name of the resource.
    • getExcludedHypernyms

      public Set<String> getExcludedHypernyms()
    • isDiskBufferEnabled

      public boolean isDiskBufferEnabled()
    • setExcludedHypernyms

      public void setExcludedHypernyms(Set<String> excludedHypernyms)