An if function is pretty simple - you write a test condition that will produce a true or false value when evaluated. If true, it will execute one set of functions that you designate, if false, another.
Or, in pseudocode:
if (<test condition>,
<execute these functions if true>,
<execute these functions if false>)
An if function is great if you want to only edit certain cells in a column, but not others. The hardest part, though, is writing the test condition. Basically, all you're really doing is trying to stack functions together to make GREL spit out a boolean. Here are a few hints to help write the test conditions.
Showing posts with label tutorial. Show all posts
Showing posts with label tutorial. Show all posts
Thursday, August 24, 2017
Monday, July 17, 2017
Walkthrough on writing a complex if function
Say
that from this sample data of a 538 field from video game records,
you're only supposed to remove "System requirements" from
the entries with a video game console:
System
requirements: Nintendo 64
System
requirements: Nintendo 64
System
requirements: Nintendo 64; designed for N64 Rumble Pak
System
requirements: PlayStation 2
System
requirements: PlayStation 2
System
requirements: Windows 95/98; 133MHz Pentium or faster processor;
Windows 95/98; 64MB RAM; Microsoft DirectX 6.0 (included); quad speed
CD-ROM drive; PCI or AGP graphics card; 4MB 3D accelerator for 3D
graphics support (optional); 16-bit sound card; keyboard and mouse;
joystick (optional); gamepad (optional)
System
requirements: PlayStation 2
System
requirements: PlayStation 2, memory card (for PS2) 94 KB
System
requirements: PlayStation 2
System
requirements: Nintendo 64. Designed for N64 Rumble Pak
System
requirements: Nintendo Entertainment System
System
requirements: Windows 98SW/ME/2000/XP; Pentium III 800 MHz or faster;
256 MB RAM; ; 2.5 GB free hard disk space; 32 MB hardware T&L
compatible video card; Windows compatible sound card; DirectX version
9.0c (included) or higher; 8x or faster CD-ROM drive
System requirements: PlayStation 2, memory card (for PS2) 177 KB
Monday, July 3, 2017
Introduction to loops and forRange tutorial with variable data
Problem : I have a column of cells with variable date ranges:
1907-1913
1910-1911
1908-1911
etc.
The cells have to be converted to:
1907; 1908; 1909; 1910; 1911; 1912; 1913
1910; 1911
1908; 1909; 1910; 1911
etc.
Open Refine can be used to convert this. Using add column based on this column, you would use the following GREL command:
forRange(toNumber(substring(value, 0,4)), toNumber(substring(value, 5,9)) + 1, 1, currentYear, currentYear).join("; ")
Yes, it looks daunting. But let's break it down, starting with the forRange command:
1907-1913
1910-1911
1908-1911
etc.
The cells have to be converted to:
1907; 1908; 1909; 1910; 1911; 1912; 1913
1910; 1911
1908; 1909; 1910; 1911
etc.
Open Refine can be used to convert this. Using add column based on this column, you would use the following GREL command:
forRange(toNumber(substring(value, 0,4)), toNumber(substring(value, 5,9)) + 1, 1, currentYear, currentYear).join("; ")
Yes, it looks daunting. But let's break it down, starting with the forRange command:
Introduction to Arrays
Update 7/28/17: I've fixed up this post because when I first wrote it, I didn't realize what Open Refine's convention was for naming arrays.
You've probably heard a lot about arrays when working with Open Refine, but what exactly is it?
First of all, I need to explain how software computing works before I can explain the array functionality. When any sort of software needs to process data, it has to break it down into chunks that it can understand. The chunks are in the computer's equivalent of headspace -- much like when you're trying to figure things out in your head.
However, a computer can only process data using certain structures. There are several of these data structures, but I'm just going to cover the array.
You've probably heard a lot about arrays when working with Open Refine, but what exactly is it?
First of all, I need to explain how software computing works before I can explain the array functionality. When any sort of software needs to process data, it has to break it down into chunks that it can understand. The chunks are in the computer's equivalent of headspace -- much like when you're trying to figure things out in your head.
However, a computer can only process data using certain structures. There are several of these data structures, but I'm just going to cover the array.
Labels:
arrays,
arrays-outputting,
info dump,
theory,
tutorial
Subscribe to:
Posts (Atom)