Coverage Report - org.apache.any23.extractor.xpath.QuadTemplate
 
Classes in this File Line Coverage Branch Coverage Complexity
QuadTemplate
0%
0/28
0%
0/8
1.875
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *  http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 package org.apache.any23.extractor.xpath;
 19  
 
 20  
 import org.apache.any23.extractor.ExtractionResult;
 21  
 import org.openrdf.model.Resource;
 22  
 import org.openrdf.model.URI;
 23  
 import org.openrdf.model.Value;
 24  
 
 25  
 import java.util.Map;
 26  
 
 27  
 /**
 28  
  * This class models a <i>NQuads</i> template,
 29  
  * that is a quadruple in which any component
 30  
  * can be a variable.
 31  
  *
 32  
  * @author Michele Mostarda (mostarda@fbk.eu)
 33  
  */
 34  
 public class QuadTemplate {
 35  
 
 36  
     private final TemplateSubject subject;
 37  
 
 38  
     private final TemplatePredicate predicate;
 39  
 
 40  
     private final TemplateObject object;
 41  
 
 42  
     private final TemplateGraph graph;
 43  
 
 44  
     /**
 45  
      * Constructor.
 46  
      *
 47  
      * @param subject not <code>null</code> subject template.
 48  
      * @param predicate not <code>null</code> predicate template.
 49  
      * @param object not <code>null</code> object template.
 50  
      * @param graph graph template, can be <code>null</code>.
 51  
      */
 52  
     public QuadTemplate(
 53  
             TemplateSubject subject, TemplatePredicate predicate, TemplateObject object, TemplateGraph graph
 54  0
     ) {
 55  0
         if(subject == null) {
 56  0
             throw new NullPointerException("subject term cannot be null.");
 57  
         }
 58  0
         if(predicate == null) {
 59  0
             throw new NullPointerException("predicate term cannot be null.");
 60  
         }
 61  0
         if(object == null) {
 62  0
             throw new NullPointerException("object term cannot be null.");
 63  
         }
 64  
 
 65  0
         this.subject   = subject;
 66  0
         this.predicate = predicate;
 67  0
         this.object    = object;
 68  0
         this.graph     = graph;
 69  0
     }
 70  
 
 71  
     /**
 72  
      * Constructor for template with no graph.
 73  
      *
 74  
      * @param subject
 75  
      * @param predicate
 76  
      * @param object
 77  
      */
 78  
     public QuadTemplate(TemplateSubject subject, TemplatePredicate predicate, TemplateObject object) {
 79  0
         this(subject, predicate, object, null);
 80  0
     }
 81  
 
 82  
     /**
 83  
      * @return the template subject.
 84  
      */
 85  
     public TemplateSubject getSubject() {
 86  0
         return subject;
 87  
     }
 88  
 
 89  
     /**
 90  
      * @return the template predicate.
 91  
      */
 92  
     public TemplatePredicate getPredicate() {
 93  0
         return predicate;
 94  
     }
 95  
 
 96  
     /**
 97  
      * @return the template object.
 98  
      */
 99  
     public TemplateObject getObject() {
 100  0
         return object;
 101  
     }
 102  
 
 103  
     /**
 104  
      * @return the template graph, can be <code>null</code>.
 105  
      */
 106  
     public TemplateGraph getGraph() {
 107  0
         return graph;
 108  
     }
 109  
 
 110  
     /**
 111  
      * Prints out this quad template in the given {@link org.apache.any23.extractor.ExtractionResult}, using
 112  
      * the passed <i>variableAssignment</i> to expand variables.
 113  
      *
 114  
      * @param er extraction result instance on which write the quad produced by this template.
 115  
      * @param variableAssignment the assignment used to expand variables.
 116  
      */
 117  
     public void printOut(ExtractionResult er, Map<String,String> variableAssignment) {
 118  0
         final Resource s = subject.getValue(variableAssignment);
 119  0
         final URI p      = predicate.getValue(variableAssignment);
 120  0
         final Value o    = object.getValue(variableAssignment);
 121  0
         if(graph != null) {
 122  0
             final URI g = graph.getValue(variableAssignment);
 123  0
             er.writeTriple(s, p, o, g);
 124  0
         } else {
 125  0
             er.writeTriple(s, p, o);
 126  
         }
 127  0
     }
 128  
 
 129  
     @Override
 130  
     public String toString() {
 131  0
         return String.format("%s %s %s %s", subject, predicate, object, graph);
 132  
     }
 133  
 
 134  
 }