def getConcepts(self): """ Return a list of concepts """ return [ skos.Concept('uri1', 'prefLabel1', 'definition1'), skos.Concept('uri2', 'prefLabel2', 'definition2'), skos.Concept('uri1', 'prefLabel1', 'definition1') # repeat a concept ]
def getChildConcepts(self): """ Return a collection of concepts """ return skos.Concepts([ skos.Concept('uri1', 'prefLabel1', 'definition1', 'notation1'), skos.Concept('uri2', 'prefLabel2', 'definition2', 'notation2') ])
def testAdd(self): # add an existing child existing = skos.Concept('uri1', 'prefLabel1', 'definition1') self.concepts.add(existing) self.assertEqual(len(self.concepts), 2) # add a new child new = skos.Concept('uri3', 'prefLabel3', 'definition3') self.concepts.add(new) self.assertEqual(len(self.concepts), 3)
def testDiscard(self): # discard an existing child existing = skos.Concept('uri1', 'prefLabel1', 'definition1') self.assertIn(existing, self.concepts) self.concepts.discard(existing) self.assertEqual(len(self.concepts), 1) self.assertNotIn(existing, self.concepts) # discard a non-extant concept external = skos.Concept('uri3', 'prefLabel3', 'definition3') self.assertNotIn(external, self.concepts) self.concepts.discard(external) self.assertEqual(len(self.concepts), 1)
def testEqual(self): self.assertEqual(self.obj, self.getTestObj()) other = skos.Concept('other uri', 'other prefLabel', 'other definition', 'other notation') self.assertNotEqual(self.obj, other) # compare against an instance with a different interface. Use # `assertFalse` as `assertNotEqual` seems to catch # `AttributeErrors`. self.assertFalse(self.obj == 'other object')
def render(self): if self.view == 'skos': if self.format == 'text/html': cc = skos.Concept(self.uri) return render_template('skos.html', title=cc.label, c=cc, skos_class=('http://www.w3.org/2004/02/skos/core#Concept', 'Concept'), formats=[(format, format.split('/')[-1]) for format in self.views.get('skos').formats]) elif self.format in Renderer.RDF_MIMETYPES: return self._render_skos_rdf() else: # In theory, this line should never execute because if an invalid format has been entered, the pyldapi # will default to the default format. In this case, The default format for the default view (skos) is # text/html. raise RuntimeError('Invalid format error') else: # Let pyldapi handle the rendering of the 'alternates' view. return super(ConceptRenderer, self).render()
def testIn(self): child = skos.Concept('uri1', 'prefLabel1', 'definition1') self.assertIn(child, self.concepts) self.assertIn(child.uri, self.concepts)
def getConcepts(self): concepts = [ skos.Concept('uri1', 'prefLabel1', 'definition1', 'notation1', 'altLabel1'), skos.Concept('uri2', 'prefLabel2', 'definition2', 'notation2', 'altLabel2') ] return concepts
def getTestObj(self): return skos.Concept('uri', 'prefLabel', 'definition', 'notation', 'altLabel')