package units
Provides classes representing information units (structured and textual units) and meta information (like tf vectors and type mentions).
Overview
Information units (implementing the trait InformationUnit) represent paragraphs in a given document, which can be narrative text (NaturalLanguageTaggedUnit) or structured fragments (CodeTaggedUnit). Each information unit exports a set of meta-information (implementing the MetaInformation trait), which are ready made semantic data for simple analyses. This version of StORMeD provides the following meta-information:
- NaturalLanguageMetaInformation for a natural language view of the information unit (can be used also for code);
- CodeTypesMetaInformation providing the mentioned types in the unit;
- CodeVariablesMetaInformation providing the mentioned variables;
- CodeInvocationMetaInformation providing the invoked methods in the unit.
In the case a meta information is not provided for a unit, a AbsentMetaInformation object can be also provided.
Tutorial
Suppose you want to get all the types mentioned in a question. First, you retrieve all its information units:
scala> val questionUnits = question.units questionUnits: Seq[ch.usi.inf.reveal.parsing.units.InformationUnit] = ...
Instead of using the visitor to on all the HASTs, you can exploit the ready made data provided by the meta information.
For example, to get all the meta information for units, you can use flatMap
:
scala> import ch.usi.inf.reveal.parsing.units._ import ch.usi.inf.reveal.parsing.units._ scala> val questionMetaInfos = questionUnits.flatMap { _.metaInformation } questionMetaInfos: Seq[ch.usi.inf.reveal.parsing.units.MetaInformation] = List(...)
You need now to filter to get only the CodeTypesMetaInformation, and then you can get, for example, the mentioned qualified Types:
scala> val codeTypesMetaInfos = questionMetaInfos.filter { _.isInstanceOf[CodeTypesMetaInformation] }.asInstanceOf[Seq[CodeTypesMetaInformation]] codeTypesMetaInfos: Seq[ch.usi.inf.reveal.parsing.units.CodeTypesMetaInformation] = List(...) scala> val types = codeTypesMetaInfos.flatMap { _.qualifiedTypes }.distinct types: Seq[ch.usi.inf.reveal.parsing.model.java.ReferenceTypeNode] = List(...)
- Alphabetic
- By Inheritance
- units
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
case class
AbsentMetaInformation
() extends MetaInformation[AbsentMetaInformation] with Product with Serializable
A special meta information object that represents the absence of a given meta information.
-
case class
CodeIdentifiersMetaInformation
(identifiers: List[IdentifierNode]) extends MetaInformation[CodeIdentifiersMetaInformation] with Product with Serializable
The meta information representing identifiers.
The meta information representing identifiers.
- identifiers
a list of identifier nodes.
- case class CodeIdentifiersMetaInformationBuilder (parsedCode: HASTNode) extends MetaInformationBuilder[CodeIdentifiersMetaInformation] with Product with Serializable
-
case class
CodeInvocationMetaInformation
(invocations: List[MethodInvocationNode]) extends MetaInformation[CodeInvocationMetaInformation] with Product with Serializable
The meta information representing code invocations.
The meta information representing code invocations.
- invocations
a list of method invocation nodes.
- case class CodeInvocationMetaInformationBuilder (parsedCode: HASTNode) extends MetaInformationBuilder[CodeInvocationMetaInformation] with Product with Serializable
-
case class
CodeMethodDeclarationsMetaInformation
(declarations: List[MethodDeclarationNode]) extends MetaInformation[CodeMethodDeclarationsMetaInformation] with Product with Serializable
The meta information representing method declarations.
The meta information representing method declarations.
- declarations
a list of method declarations.
- case class CodeMethodDeclarationsMetaInformationBuilder (parsedCode: HASTNode) extends MetaInformationBuilder[CodeMethodDeclarationsMetaInformation] with Product with Serializable
- case class CodeReadabilityMetaInformation (grade: Double, underlyingNumberOfUnits: Double = 1.0) extends MetaInformation[CodeReadabilityMetaInformation] with Product with Serializable
- case class CodeReadabilityMetaInformationBuilder (unit: CodeTaggedUnit) extends MetaInformationBuilder[CodeReadabilityMetaInformation] with Product with Serializable
-
case class
CodeTaggedUnit
(id: String, astNode: HASTNodeSequence, rawText: String, source: SourceInfo, metaInformation: Seq[MetaInformation[_]] = Seq()) extends InformationUnit with Product with Serializable
An information unit representing a paragraph mainly containing code.
An information unit representing a paragraph mainly containing code.
- astNode
a sequence of HAST nodes representing the HAST of the unit.
-
case class
CodeTypeDeclarationsMetaInformation
(classes: List[ClassDeclarationNode], interfaces: List[InterfaceDeclarationNode], enums: List[EnumDeclarationNode]) extends MetaInformation[CodeTypeDeclarationsMetaInformation] with Product with Serializable
The meta information representing code type declarations.
The meta information representing code type declarations.
- classes
a list of class declarations.
- interfaces
a list of interface declarations.
- enums
a list of enums.
- case class CodeTypeDeclarationsMetaInformationBuilder (parsedCode: HASTNode) extends MetaInformationBuilder[CodeTypeDeclarationsMetaInformation] with Product with Serializable
-
case class
CodeTypesMetaInformation
(qualifiedTypes: List[ReferenceTypeNode], simpleTypes: List[ReferenceTypeNode], basicTypes: List[PrimitiveTypeNode], arrayTypes: List[ArrayTypeNode]) extends MetaInformation[CodeTypesMetaInformation] with Product with Serializable
Contains all the declared and used types in an information unit.
Contains all the declared and used types in an information unit.
The code types metainformation represents all the declared and used types in an information unit. For simplicity, this metainformation splits the types into qualified, simple, basic, and array types.
- qualifiedTypes
a list of qualified reference type nodes.
- simpleTypes
a list of simple types.
- basicTypes
a list of primitive types.
- arrayTypes
a list of array types.
-
case class
CodeTypesMetaInformationBuilder
(parsedCode: HASTNode) extends MetaInformationBuilder[CodeTypesMetaInformation] with Product with Serializable
Builds the code type metainformation.
Builds the code type metainformation.
The code type metainformation builder collects all the declared and used types in an information unit. In the case of array types, which can be only used and not declared, the contained is also collected separately, as a qualified or simple type. In the case of generic types, the raw types are *not* collected. Generic classes and interfaces are present with type arguments corresponding to the same type parameters used in the declaration, and not with the corresponding erased or raw types.
-
case class
CodeVariablesMetaInformation
(variables: List[VariableDeclarationNode]) extends MetaInformation[CodeVariablesMetaInformation] with Product with Serializable
The meta information representing the code variable declarations.
The meta information representing the code variable declarations.
- variables
the variable declarations in the information unit.
- case class CodeVariablesMetaInformationBuilder (parsedCode: HASTNode) extends MetaInformationBuilder[CodeVariablesMetaInformation] with Product with Serializable
-
sealed
trait
InformationUnit
extends JsonSerializable
A generic trait for information units.
- case class JsonMembersMetaInformationBuilder (parsedCode: HASTNode) extends MetaInformationBuilder[JsonMetaInformation] with Product with Serializable
- case class JsonMetaInformation (members: List[JsonMemberNode]) extends MetaInformation[JsonMetaInformation] with Product with Serializable
-
trait
MetaInformation
[T <: MetaInformation[T]] extends JsonSerializable
Common trait for meta information.
- trait MetaInformationBuilder [T <: MetaInformation[T]] extends AnyRef
- case class MetaInformationBuilderParameters (luceneIndex: LuceneIndex) extends Product with Serializable
-
case class
NaturalLanguageMetaInformation
(tfMap: Map[String, Int]) extends MetaInformation[NaturalLanguageMetaInformation] with Product with Serializable
The meta information for natural language, containing the term frequency map.
The meta information for natural language, containing the term frequency map.
- tfMap
the term frequency map for the natural language component of the information unit.
- case class NaturalLanguageMetaInformationBuilder (rawText: String) extends MetaInformationBuilder[NaturalLanguageMetaInformation] with Product with Serializable
-
case class
NaturalLanguageTaggedUnit
(id: String, astNode: HASTNodeSequence, rawText: String, source: SourceInfo, metaInformation: Seq[MetaInformation[_]] = Seq()) extends InformationUnit with Product with Serializable
An information unit representing a paragraph mainly containing natural language.
An information unit representing a paragraph mainly containing natural language.
- astNode
a sequence of HAST nodes representing the HAST of the unit.
- case class SentimentAnalysisMetaInformation (averageLevel: nlp.SentimentLevel.Value, underlyingNumberOfUnits: Double = 1.0) extends MetaInformation[SentimentAnalysisMetaInformation] with Product with Serializable
- case class SentimentAnalysisMetaInformationBuilder (unit: NaturalLanguageTaggedUnit) extends MetaInformationBuilder[SentimentAnalysisMetaInformation] with Product with Serializable
- case class TextReadabilityMetaInformation (fleshReadingEaseScore: Double, fleshKincaidGradeLevel: Double, automatedReadingIndex: Double, gunningFogIndex: Double, smogIndex: Double, colemanLiauIndex: Double, underlyingNumberOfUnits: Double = 1.0) extends MetaInformation[TextReadabilityMetaInformation] with Product with Serializable
- case class TextReadabilityMetaInformationBuilder (unit: NaturalLanguageTaggedUnit) extends MetaInformationBuilder[TextReadabilityMetaInformation] with Product with Serializable
- case class XmlTagsMetaInformation (composed: List[XmlComposedNode], single: List[XmlSingleNode]) extends MetaInformation[XmlTagsMetaInformation] with Product with Serializable
- case class XmlTagsMetaInformationBuilder (parsedCode: HASTNode) extends MetaInformationBuilder[XmlTagsMetaInformation] with Product with Serializable
Value Members
-
object
InformationUnit
Companion object with utility methods for information units.
-
object
InformationUnit2MetaInformationBuilder
A builder for meta information.